File: 616e2e26d1c4b779b6d7332308db39a1944556d7.patch

package info (click to toggle)
lua-dbi 0.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 416 kB
  • sloc: ansic: 3,018; sql: 220; makefile: 114
file content (29 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
From 616e2e26d1c4b779b6d7332308db39a1944556d7 Mon Sep 17 00:00:00 2001
From: Nilesh Govindrajan <me@nileshgr.com>
Date: Sat, 8 Dec 2018 09:37:41 +0530
Subject: [PATCH] Fix memory leak in statement:execute by calling PQclear

There is a memory leak in statement:execute because the old result is not cleared. So the script keeps on hogging memory.
Check old result and if it is OK status then call PQclear before assigning new result to statement->result.
---
 dbd/postgresql/statement.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dbd/postgresql/statement.c b/dbd/postgresql/statement.c
index acac91c..9e219d7 100644
--- a/dbd/postgresql/statement.c
+++ b/dbd/postgresql/statement.c
@@ -218,7 +218,12 @@ static int statement_execute(lua_State *L) {
         lua_pushfstring(L, DBI_ERR_BINDING_EXEC, PQresultErrorMessage(result));
         return 2;
     }
-    
+
+    if (statement->result) {
+        status = PQresultStatus (statement->result);
+	if (status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK)
+            PQclear (statement->result);
+    }
     statement->result = result;
 
     lua_pushboolean(L, 1);