Code

frontend: Fixed a memory leak in the connection context handler.
authorSebastian Harl <sh@tokkee.org>
Fri, 11 Apr 2014 07:13:55 +0000 (09:13 +0200)
committerSebastian Harl <sh@tokkee.org>
Fri, 11 Apr 2014 07:13:55 +0000 (09:13 +0200)
Previously, the ownership was not taken away from the thread-specific data
aftter removing the connection from the current context, thus leaking each
connection object.

src/frontend/connection.c

index 69c71edbd3e6f7ac9e5876841d9237f738267ab5..1fa4ba98c6888a726f8e921cce82f9d7e1d8900a 100644 (file)
@@ -185,7 +185,13 @@ sdb_conn_ctx_init(void)
 static void
 sdb_conn_set_ctx(sdb_conn_t *conn)
 {
+       sdb_conn_t *old;
+
        sdb_conn_ctx_init();
+
+       old = pthread_getspecific(conn_ctx_key);
+       if (old)
+               sdb_object_deref(SDB_OBJ(old));
        if (conn)
                sdb_object_ref(SDB_OBJ(conn));
        pthread_setspecific(conn_ctx_key, conn);