Code

78bfd76545aa4e6d300189c44d98e557c04dd43b
[pkg-collectd.git] / debian / patches / postgresql_writer_memleak.dpatch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## postgresql_writer_memleak.dpatch by Sebastian Harl <sh@tokkee.org>
3 ##
4 ## DP: postgresql plugin: Fixed a memory leak occurring on every write.
6 @DPATCH@
8 diff a/src/postgresql.c b/src/postgresql.c
9 --- a/src/postgresql.c
10 +++ b/src/postgresql.c
11 @@ -900,10 +900,10 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl,
12  
13                 if ((PGRES_COMMAND_OK != PQresultStatus (res))
14                                 && (PGRES_TUPLES_OK != PQresultStatus (res))) {
15 +                       PQclear (res);
16 +
17                         if ((CONNECTION_OK != PQstatus (db->conn))
18                                         && (0 == c_psql_check_connection (db))) {
19 -                               PQclear (res);
20 -
21                                 /* try again */
22                                 res = PQexecParams (db->conn, writer->statement,
23                                                 STATIC_ARRAY_SIZE (params), NULL,
24 @@ -912,6 +912,7 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl,
25  
26                                 if ((PGRES_COMMAND_OK == PQresultStatus (res))
27                                                 || (PGRES_TUPLES_OK == PQresultStatus (res))) {
28 +                                       PQclear (res);
29                                         success = 1;
30                                         continue;
31                                 }
32 @@ -932,6 +933,8 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl,
33                         pthread_mutex_unlock (&db->db_lock);
34                         return -1;
35                 }
36 +
37 +               PQclear (res);
38                 success = 1;
39         }
40