Skip to content

Commit 3151c26

Browse files
committed
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 a6eabec, that has played with the order of some ecpg_strdup() calls in this code path.
1 parent 793928c commit 3151c26

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/interfaces/ecpg/ecpglib/prepare.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,10 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
603603
prep = ecpg_find_prepared_statement(stmtID, con, NULL);
604604
/* This prepared name doesn't exist on this connection. */
605605
if (!prep && !prepare_common(lineno, con, stmtID, query))
606+
{
607+
ecpg_free(*name);
606608
return false;
609+
}
607610

608611
}
609612
else
@@ -619,11 +622,17 @@ ecpg_auto_prepare(int lineno, const char *connection_name, const int compat, cha
619622
return false;
620623

621624
if (!ECPGprepare(lineno, connection_name, 0, stmtID, query))
625+
{
626+
ecpg_free(*name);
622627
return false;
628+
}
623629

624630
entNo = AddStmtToCache(lineno, stmtID, connection_name, compat, query);
625631
if (entNo < 0)
632+
{
633+
ecpg_free(*name);
626634
return false;
635+
}
627636
}
628637

629638
/* increase usage counter */

0 commit comments

Comments
 (0)