Commit e2a755f
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.1 parent 4da7859 commit e2a755f
2 files changed
+19
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
3 | 10 | | |
4 | 11 | | |
5 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
| |||
1499 | 1501 | | |
1500 | 1502 | | |
1501 | 1503 | | |
1502 | | - | |
| 1504 | + | |
1503 | 1505 | | |
1504 | 1506 | | |
1505 | 1507 | | |
| |||
1513 | 1515 | | |
1514 | 1516 | | |
1515 | 1517 | | |
1516 | | - | |
| 1518 | + | |
1517 | 1519 | | |
1518 | 1520 | | |
1519 | 1521 | | |
| |||
1527 | 1529 | | |
1528 | 1530 | | |
1529 | 1531 | | |
1530 | | - | |
| 1532 | + | |
1531 | 1533 | | |
1532 | | - | |
| 1534 | + | |
1533 | 1535 | | |
1534 | 1536 | | |
1535 | 1537 | | |
| |||
1542 | 1544 | | |
1543 | 1545 | | |
1544 | 1546 | | |
1545 | | - | |
1546 | | - | |
1547 | | - | |
| 1547 | + | |
| 1548 | + | |
1548 | 1549 | | |
1549 | 1550 | | |
1550 | 1551 | | |
1551 | 1552 | | |
1552 | | - | |
1553 | | - | |
1554 | | - | |
| 1553 | + | |
| 1554 | + | |
1555 | 1555 | | |
1556 | | - | |
| 1556 | + | |
1557 | 1557 | | |
1558 | 1558 | | |
1559 | 1559 | | |
1560 | | - | |
| 1560 | + | |
1561 | 1561 | | |
1562 | 1562 | | |
1563 | 1563 | | |
| |||
0 commit comments