Django

Code

Ticket #11246 (closed: fixed)

Opened 8 months ago

Last modified 8 months ago

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

Reported by: andrewfox Assigned to: jbronn
Milestone: Component: GIS
Version: 1.0 Keywords: geodjango, gis, geoip, ctype, leak, file handle
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

06/02/09 15:24:40 changed by anonymous

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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)

06/02/09 23:09:42 changed by jbronn

  • owner changed from nobody to jbronn.
  • component changed from Contrib apps to GIS.

06/10/09 21:45:48 changed by jbronn

  • status changed from new to closed.
  • resolution set to fixed.

(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.

06/10/09 21:53:33 changed by jbronn

(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.


Add/Change #11246 (contrib/gis/utils/geoip.py GeoIP leaks file handles)




Change Properties
Action