Commit d613861b authored by Bruce Momjian's avatar Bruce Momjian

pg_dump: fix subtle memory leak in func and arg signature processing

parent 3f05beda
...@@ -9604,7 +9604,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9604,7 +9604,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
PQExpBuffer asPart; PQExpBuffer asPart;
PGresult *res; PGresult *res;
char *funcsig; /* identity signature */ char *funcsig; /* identity signature */
char *funcfullsig; /* full signature */ char *funcfullsig = NULL; /* full signature */
char *funcsig_tag; char *funcsig_tag;
char *proretset; char *proretset;
char *prosrc; char *prosrc;
...@@ -9912,13 +9912,10 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9912,13 +9912,10 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
funcsig = format_function_arguments(finfo, funciargs, false); funcsig = format_function_arguments(finfo, funciargs, false);
} }
else else
{
/* pre-8.4, do it ourselves */ /* pre-8.4, do it ourselves */
funcsig = format_function_arguments_old(fout, funcsig = format_function_arguments_old(fout,
finfo, nallargs, allargtypes, finfo, nallargs, allargtypes,
argmodes, argnames); argmodes, argnames);
funcfullsig = funcsig;
}
funcsig_tag = format_function_signature(fout, finfo, false); funcsig_tag = format_function_signature(fout, finfo, false);
...@@ -9929,7 +9926,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9929,7 +9926,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
fmtId(finfo->dobj.namespace->dobj.name), fmtId(finfo->dobj.namespace->dobj.name),
funcsig); funcsig);
appendPQExpBuffer(q, "CREATE FUNCTION %s ", funcfullsig); appendPQExpBuffer(q, "CREATE FUNCTION %s ", funcfullsig ? funcfullsig :
funcsig);
if (funcresult) if (funcresult)
appendPQExpBuffer(q, "RETURNS %s", funcresult); appendPQExpBuffer(q, "RETURNS %s", funcresult);
else else
...@@ -10052,6 +10050,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -10052,6 +10050,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
destroyPQExpBuffer(labelq); destroyPQExpBuffer(labelq);
destroyPQExpBuffer(asPart); destroyPQExpBuffer(asPart);
free(funcsig); free(funcsig);
if (funcfullsig)
free(funcfullsig);
free(funcsig_tag); free(funcsig_tag);
if (allargtypes) if (allargtypes)
free(allargtypes); free(allargtypes);
...@@ -11508,7 +11508,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -11508,7 +11508,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
PQExpBuffer labelq; PQExpBuffer labelq;
PQExpBuffer details; PQExpBuffer details;
char *aggsig; /* identity signature */ char *aggsig; /* identity signature */
char *aggfullsig; /* full signature */ char *aggfullsig = NULL; /* full signature */
char *aggsig_tag; char *aggsig_tag;
PGresult *res; PGresult *res;
int i_aggtransfn; int i_aggtransfn;
...@@ -11656,11 +11656,8 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -11656,11 +11656,8 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true); aggsig = format_function_arguments(&agginfo->aggfn, funciargs, true);
} }
else else
{
/* pre-8.4, do it ourselves */ /* pre-8.4, do it ourselves */
aggsig = format_aggregate_signature(agginfo, fout, true); aggsig = format_aggregate_signature(agginfo, fout, true);
aggfullsig = aggsig;
}
aggsig_tag = format_aggregate_signature(agginfo, fout, false); aggsig_tag = format_aggregate_signature(agginfo, fout, false);
...@@ -11730,7 +11727,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -11730,7 +11727,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
aggsig); aggsig);
appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n", appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n",
aggfullsig, details->data); aggfullsig ? aggfullsig : aggsig, details->data);
appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig); appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig);
...@@ -11773,6 +11770,8 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -11773,6 +11770,8 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
agginfo->aggfn.rolname, agginfo->aggfn.proacl); agginfo->aggfn.rolname, agginfo->aggfn.proacl);
free(aggsig); free(aggsig);
if (aggfullsig)
free(aggfullsig);
free(aggsig_tag); free(aggsig_tag);
PQclear(res); PQclear(res);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment