Skip to content

Commit

Permalink
Untrack the connection before closing to avoid possible double-free
Browse files Browse the repository at this point in the history
From Gangadharan S.A. Fixes issue psycopg#166.
  • Loading branch information
dvarrazzo committed Jun 20, 2013
1 parent 9f4b5b3 commit 889b1d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -5,6 +5,8 @@ What's new in psycopg 2.5.1
declared (:ticket:`#146`).
- Fixed comparison of `Range` with non-range objects (:ticket:`#164`).
Thanks to Chris Withers for the patch.
- Fixed double-free on connection dealloc (:ticket:`#166`). Thanks to
Gangadharan S.A. for the report and fix suggestion.


What's new in psycopg 2.5
Expand Down
7 changes: 5 additions & 2 deletions psycopg/connection_type.c
Expand Up @@ -1128,10 +1128,13 @@ connection_dealloc(PyObject* obj)
{
connectionObject *self = (connectionObject *)obj;

conn_close(self);

/* Make sure to untrack the connection before calling conn_close, which may
* allow a different thread to try and dealloc the connection again,
* resulting in a double-free segfault (ticket #166). */
PyObject_GC_UnTrack(self);

conn_close(self);

if (self->weakreflist) {
PyObject_ClearWeakRefs(obj);
}
Expand Down

0 comments on commit 889b1d8

Please sign in to comment.