Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#11246 closed (fixed)

contrib/gis/utils/geoip.py GeoIP leaks file handles

Reported by: andrewfox Owned by: jbronn
Component: GIS Version: 1.0
Severity: Keywords: geodjango, gis, geoip, ctype, leak, file handle
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The GeoIP wrapper object in contrib.gis.utils.geoip.py does not seem to clean the referenced GeoIP c library database fopen'd files up. The init of GeoIP proceeds to load the city and the country dbs via the geoip c library in line 188 but does not ever seem to properly cleanup the opened dbs by calling the GeoIP_delete function in the same C library. This leaves file handles open to the various dat files which can overwealm the ulimits for certain process configurations.

Workaround is to manually call the delete functon on the self._city and self._country via ctypes but seems like it should be handled by the del of the GeoIP object.

Change History (4)

comment:1 by anonymous, 16 years ago

Example of we patched the leak by subclassing GeoIP:

from django.contrib.gis.utils import GeoIP
from django.contrib.gis.utils.geoip import lgeoip

geoip_delete = lgeoip.GeoIP_delete
geoip_delete.restype = None

class BGeoIP(GeoIP):

def del(self):

if hasattr(self, '_country') and self._country is not None and \

self._country:

geoip_delete(self._country)

if hasattr(self, '_city') and self._city is not None and \

self._city:

geoip_delete(self._city)

comment:2 by jbronn, 16 years ago

Component: Contrib appsGIS
Owner: changed from nobody to jbronn

comment:3 by jbronn, 16 years ago

Resolution: fixed
Status: newclosed

(In [10979]) Fixed #11245, #11246 -- Fixed validity check of GeoIP pointers and leaking of their references; also clarified initialization, fixed a stale test, added comments about version compatibility, and did some whitespace cleanup.

comment:4 by jbronn, 16 years ago

(In [10980]) [1.0.X] Fixed #11245, #11246 -- Fixed validity check of GeoIP pointers and leaking of their references; also clarified initialization, fixed a stale test, added comments about version compatibility, and did some whitespace cleanup.

Backport of r10979 from trunk.

Note: See TracTickets for help on using tickets.
Back to Top