Code

postgresql plugin: Fixed a memory leak occurring on every (successful) write.
authorSebastian Harl <sh@tokkee.org>
Thu, 29 Nov 2012 08:01:37 +0000 (09:01 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 29 Nov 2012 08:01:37 +0000 (09:01 +0100)
src/postgresql.c

index 15d4666b9eaf910c2d91f80ce2552291eb9d6e45..6c9ab44e8b3379aff58dd9b0b7a4295e6b74876c 100644 (file)
@@ -900,10 +900,10 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl,
 
                if ((PGRES_COMMAND_OK != PQresultStatus (res))
                                && (PGRES_TUPLES_OK != PQresultStatus (res))) {
+                       PQclear (res);
+
                        if ((CONNECTION_OK != PQstatus (db->conn))
                                        && (0 == c_psql_check_connection (db))) {
-                               PQclear (res);
-
                                /* try again */
                                res = PQexecParams (db->conn, writer->statement,
                                                STATIC_ARRAY_SIZE (params), NULL,
@@ -912,6 +912,7 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl,
 
                                if ((PGRES_COMMAND_OK == PQresultStatus (res))
                                                || (PGRES_TUPLES_OK == PQresultStatus (res))) {
+                                       PQclear (res);
                                        success = 1;
                                        continue;
                                }
@@ -932,6 +933,8 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl,
                        pthread_mutex_unlock (&db->db_lock);
                        return -1;
                }
+
+               PQclear (res);
                success = 1;
        }