@@ -261,7 +261,7 @@ static char *convertRegProcReference(Archive *fout,
261
261
static char *getFormattedOperatorName(Archive *fout, const char *oproid);
262
262
static char *convertTSFunction(Archive *fout, Oid funcOid);
263
263
static Oid findLastBuiltinOid_V71(Archive *fout);
264
- static char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts);
264
+ static const char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts);
265
265
static void getBlobs(Archive *fout);
266
266
static void dumpBlob(Archive *fout, BlobInfo *binfo);
267
267
static int dumpBlobs(Archive *fout, void *arg);
@@ -10889,13 +10889,9 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
10889
10889
}
10890
10890
10891
10891
if (OidIsValid(tyinfo->typelem))
10892
- {
10893
- char *elemType;
10894
-
10895
- elemType = getFormattedTypeName(fout, tyinfo->typelem, zeroAsOpaque);
10896
- appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType);
10897
- free(elemType);
10898
- }
10892
+ appendPQExpBuffer(q, ",\n ELEMENT = %s",
10893
+ getFormattedTypeName(fout, tyinfo->typelem,
10894
+ zeroAsOpaque));
10899
10895
10900
10896
if (strcmp(typcategory, "U") != 0)
10901
10897
{
@@ -11698,7 +11694,7 @@ format_function_arguments_old(Archive *fout,
11698
11694
for (j = 0; j < nallargs; j++)
11699
11695
{
11700
11696
Oid typid;
11701
- char *typname;
11697
+ const char *typname;
11702
11698
const char *argmode;
11703
11699
const char *argname;
11704
11700
@@ -11737,7 +11733,6 @@ format_function_arguments_old(Archive *fout,
11737
11733
argname ? fmtId(argname) : "",
11738
11734
argname ? " " : "",
11739
11735
typname);
11740
- free(typname);
11741
11736
}
11742
11737
appendPQExpBufferChar(&fn, ')');
11743
11738
return fn.data;
@@ -11766,15 +11761,12 @@ format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
11766
11761
appendPQExpBuffer(&fn, "%s(", finfo->dobj.name);
11767
11762
for (j = 0; j < finfo->nargs; j++)
11768
11763
{
11769
- char *typname;
11770
-
11771
11764
if (j > 0)
11772
11765
appendPQExpBufferStr(&fn, ", ");
11773
11766
11774
- typname = getFormattedTypeName(fout, finfo->argtypes[j],
11775
- zeroAsOpaque);
11776
- appendPQExpBufferStr(&fn, typname);
11777
- free(typname);
11767
+ appendPQExpBufferStr(&fn,
11768
+ getFormattedTypeName(fout, finfo->argtypes[j],
11769
+ zeroAsOpaque));
11778
11770
}
11779
11771
appendPQExpBufferChar(&fn, ')');
11780
11772
return fn.data;
@@ -11818,7 +11810,6 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
11818
11810
char *prosupport;
11819
11811
char *proparallel;
11820
11812
char *lanname;
11821
- char *rettypename;
11822
11813
int nallargs;
11823
11814
char **allargtypes = NULL;
11824
11815
char **argmodes = NULL;
@@ -12175,14 +12166,10 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
12175
12166
else if (funcresult)
12176
12167
appendPQExpBuffer(q, " RETURNS %s", funcresult);
12177
12168
else
12178
- {
12179
- rettypename = getFormattedTypeName(fout, finfo->prorettype,
12180
- zeroAsOpaque);
12181
12169
appendPQExpBuffer(q, " RETURNS %s%s",
12182
12170
(proretset[0] == 't') ? "SETOF " : "",
12183
- rettypename);
12184
- free(rettypename);
12185
- }
12171
+ getFormattedTypeName(fout, finfo->prorettype,
12172
+ zeroAsOpaque));
12186
12173
12187
12174
appendPQExpBuffer(q, "\n LANGUAGE %s", fmtId(lanname));
12188
12175
@@ -12389,8 +12376,8 @@ dumpCast(Archive *fout, CastInfo *cast)
12389
12376
PQExpBuffer labelq;
12390
12377
PQExpBuffer castargs;
12391
12378
FuncInfo *funcInfo = NULL;
12392
- char *sourceType;
12393
- char *targetType;
12379
+ const char *sourceType;
12380
+ const char *targetType;
12394
12381
12395
12382
/* Skip if not to be dumped */
12396
12383
if (!cast->dobj.dump || dopt->dataOnly)
@@ -12476,9 +12463,6 @@ dumpCast(Archive *fout, CastInfo *cast)
12476
12463
NULL, "",
12477
12464
cast->dobj.catId, 0, cast->dobj.dumpId);
12478
12465
12479
- free(sourceType);
12480
- free(targetType);
12481
-
12482
12466
destroyPQExpBuffer(defqry);
12483
12467
destroyPQExpBuffer(delqry);
12484
12468
destroyPQExpBuffer(labelq);
@@ -12499,7 +12483,7 @@ dumpTransform(Archive *fout, TransformInfo *transform)
12499
12483
FuncInfo *fromsqlFuncInfo = NULL;
12500
12484
FuncInfo *tosqlFuncInfo = NULL;
12501
12485
char *lanname;
12502
- char *transformType;
12486
+ const char *transformType;
12503
12487
12504
12488
/* Skip if not to be dumped */
12505
12489
if (!transform->dobj.dump || dopt->dataOnly)
@@ -12606,7 +12590,6 @@ dumpTransform(Archive *fout, TransformInfo *transform)
12606
12590
transform->dobj.catId, 0, transform->dobj.dumpId);
12607
12591
12608
12592
free(lanname);
12609
- free(transformType);
12610
12593
destroyPQExpBuffer(defqry);
12611
12594
destroyPQExpBuffer(delqry);
12612
12595
destroyPQExpBuffer(labelq);
@@ -13898,17 +13881,11 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
13898
13881
{
13899
13882
appendPQExpBufferChar(&buf, '(');
13900
13883
for (j = 0; j < agginfo->aggfn.nargs; j++)
13901
- {
13902
- char *typname;
13903
-
13904
- typname = getFormattedTypeName(fout, agginfo->aggfn.argtypes[j],
13905
- zeroAsOpaque);
13906
-
13907
13884
appendPQExpBuffer(&buf, "%s%s",
13908
13885
(j > 0) ? ", " : "",
13909
- typname);
13910
- free(typname);
13911
- }
13886
+ getFormattedTypeName(fout,
13887
+ agginfo->aggfn.argtypes[j],
13888
+ zeroAsOpaque));
13912
13889
appendPQExpBufferChar(&buf, ')');
13913
13890
}
13914
13891
return buf.data;
@@ -18604,8 +18581,10 @@ findDumpableDependencies(ArchiveHandle *AH, DumpableObject *dobj,
18604
18581
*
18605
18582
* This does not guarantee to schema-qualify the output, so it should not
18606
18583
* be used to create the target object name for CREATE or ALTER commands.
18584
+ *
18585
+ * Note that the result is cached and must not be freed by the caller.
18607
18586
*/
18608
- static char *
18587
+ static const char *
18609
18588
getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
18610
18589
{
18611
18590
TypeInfo *typeInfo;
@@ -18616,19 +18595,19 @@ getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
18616
18595
if (oid == 0)
18617
18596
{
18618
18597
if ((opts & zeroAsOpaque) != 0)
18619
- return pg_strdup( g_opaque_type) ;
18598
+ return g_opaque_type;
18620
18599
else if ((opts & zeroAsAny) != 0)
18621
- return pg_strdup( "'any'") ;
18600
+ return "'any'";
18622
18601
else if ((opts & zeroAsStar) != 0)
18623
- return pg_strdup( "*") ;
18602
+ return "*";
18624
18603
else if ((opts & zeroAsNone) != 0)
18625
- return pg_strdup( "NONE") ;
18604
+ return "NONE";
18626
18605
}
18627
18606
18628
18607
/* see if we have the result cached in the type's TypeInfo record */
18629
18608
typeInfo = findTypeByOid(oid);
18630
18609
if (typeInfo && typeInfo->ftypname)
18631
- return pg_strdup( typeInfo->ftypname) ;
18610
+ return typeInfo->ftypname;
18632
18611
18633
18612
query = createPQExpBuffer();
18634
18613
appendPQExpBuffer(query, "SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
@@ -18642,9 +18621,14 @@ getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
18642
18621
PQclear(res);
18643
18622
destroyPQExpBuffer(query);
18644
18623
18645
- /* cache a copy for later requests */
18624
+ /*
18625
+ * Cache the result for re-use in later requests, if possible. If we
18626
+ * don't have a TypeInfo for the type, the string will be leaked once the
18627
+ * caller is done with it ... but that case really should not happen, so
18628
+ * leaking if it does seems acceptable.
18629
+ */
18646
18630
if (typeInfo)
18647
- typeInfo->ftypname = pg_strdup( result) ;
18631
+ typeInfo->ftypname = result;
18648
18632
18649
18633
return result;
18650
18634
}
0 commit comments