Skip to content

Commit

Permalink
Add explicit self.result=None in cursor.close to help prevent potenti…
Browse files Browse the repository at this point in the history
…al "double free" errors. Resolves issue #3
  • Loading branch information
Israel Brewster committed Oct 6, 2017
1 parent 1ba2b16 commit d3fc94f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions p4d/p4d.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def close(self):
"""Close the database connection"""
if self.result is not None:
self.lib4d_sql.fourd_free_result(self.result)
self.result = None
self.connection.close()
self.__description = None
self.__rowcount = -1
Expand Down Expand Up @@ -653,6 +654,7 @@ def close(self):
for cursor in self.cursors:
if cursor.result is not None and cursor.result != ffi.NULL:
lib4d_sql.fourd_free_result(cursor.result)
cursor.result = None

if self.connected:
disconnect = lib4d_sql.fourd_close(self.connptr)
Expand Down Expand Up @@ -729,12 +731,12 @@ def connect(dsn=None, user=None, password=None, host=None, database=None, port=N

if database is not None:
connect_args['database'] = database

if port is not None:
connect_args['port'] = int(port)
else:
connect_args['port'] = 19812

if 'host' not in connect_args:
# Need at least a host to connect to
raise ValueError("Host name is required")
Expand Down

0 comments on commit d3fc94f

Please sign in to comment.