maxmind/libmaxminddb — pull request #44 by autarch (2014-09-22 16:00:26+00:00)
Title: Make sure to set pointers to NULL after freeing them

The dangling pointer could incur real problem. This is the problem I run into:
My system is runing nginx built along with ngx_http_geoip2_module and libmaxminddb.
nginx is running with a configuration with a geoip2-directive specifying a file that
dose not exist. like this:

-----------------------------------------------------------
geoip2 /my/path/that/dose/not/exist/maxmind-country.mmdb {
$geoip2_data_country_code default=US country iso_code;
$geoip2_data_country_name country names en;
}
-----------------------------------------------------------

When Nginx is launched with this configuration, ngx_http_geoip2_module call
MMDB_open() which in turn calls free_mmdb_struct() as MMDB_open() was not
successfully open the specified .mmdb file.

Nginx then exit, calling ngx_http_geoip2_cleanup() which call MMDB_close(), which
call free_mmdb_struct().

NOTE that in this senario, free_mmdb_struct() is called *TWICE* upon the same
mmdb! The first call to free_mmdb_struct() yields bunch of dangling pointers, and
the 2nd call to free_mmdb_struct() will call free() on these dangling pointers.

This fix is just to set those pointer NULL right after the object they pointing
to are deallocated.