miniupnp icon indicating copy to clipboard operation
miniupnp copied to clipboard

miniupnpd: potential dereference of NULL ; potential double free ; missing fclose

Open Coeur opened this issue 9 months ago • 1 comments

This fixes three Xcode analyser warnings.

  1. The first one is trivial: a missing fclose on each early return.

The other two are more tricky and depends if ary_options is NULL or not.

  1. If ary_options is not null, then there is a double free: once on free(ary_options) then again on realloc(ary_options, ...). Since we want an optimal realloc, we don't want to prematurely add some ary_options = NULL right after free. Consequently, it's best to remove the free.

  2. If ary_options is NULL already, then the analyser is confused by a false positive where num_options would be non-zero at the start of the loop. To resolve that, we can set num_options to zero unconditionally.

Coeur avatar May 31 '25 16:05 Coeur

ping @miniupnp

Coeur avatar Nov 09 '25 13:11 Coeur