Code

Opened 5 years ago

Closed 5 years ago

Last modified 5 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: UI/UX:

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 (0)

Change History (4)

comment:1 Changed 5 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 5 years ago by jbronn

  • Component changed from Contrib apps to GIS
  • Owner changed from nobody to jbronn

comment:3 Changed 5 years ago by jbronn

  • Resolution set to fixed
  • Status changed from new to closed

(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 Changed 5 years ago 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 Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.