summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier2025-07-27 23:38:24 +0000
committerMichael Paquier2025-07-27 23:38:24 +0000
commit3151c264d460c0be09131ce90529073631d70ae8 (patch)
treea28da48f00781968a81ba19fd5f9b37b117b59b6 /src
parent793928c2d5ac8e60e1e4054fa3b986369777896d (diff)
ecpg: Fix memory leaks in ecpg_auto_prepare()
This routines includes three code paths that can fail, with the allocated prepared statement name going out of scope. Per report from Coverity. Oversight in commit a6eabec6808c, that has played with the order of some ecpg_strdup() calls in this code path.
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/ecpg/ecpglib/prepare.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/ecpglib/prepare.c b/src/interfaces/ecpg/ecpglib/prepare.c
index dd6fd1fe7f4..06f0135813b 100644
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -603,7 +603,10 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
prep = ecpg_find_prepared_statement(stmtID, con, NULL);
/* This prepared name doesn't exist on this connection. */
if (!prep && !prepare_common(lineno, con, stmtID, query))
+ {
+ ecpg_free(*name);
return false;
+ }
}
else
@@ -619,11 +622,17 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
return false;
if (!ECPGprepare(lineno, connection_name, 0, stmtID, query))
+ {
+ ecpg_free(*name);
return false;
+ }
entNo = AddStmtToCache(lineno, stmtID, connection_name, compat, query);
if (entNo < 0)
+ {
+ ecpg_free(*name);
return false;
+ }
}
/* increase usage counter */