@@ -255,7 +255,7 @@ static char *convertRegProcReference(Archive *fout,
255
255
static char *getFormattedOperatorName(Archive *fout, const char *oproid);
256
256
static char *convertTSFunction(Archive *fout, Oid funcOid);
257
257
static Oid findLastBuiltinOid_V71(Archive *fout);
258
- static char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts);
258
+ static const char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts);
259
259
static void getBlobs(Archive *fout);
260
260
static void dumpBlob(Archive *fout, BlobInfo *binfo);
261
261
static int dumpBlobs(Archive *fout, void *arg);
@@ -11009,13 +11009,9 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
11009
11009
}
11010
11010
11011
11011
if (OidIsValid(tyinfo->typelem))
11012
- {
11013
- char *elemType;
11014
-
11015
- elemType = getFormattedTypeName(fout, tyinfo->typelem, zeroIsError);
11016
- appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType);
11017
- free(elemType);
11018
- }
11012
+ appendPQExpBuffer(q, ",\n ELEMENT = %s",
11013
+ getFormattedTypeName(fout, tyinfo->typelem,
11014
+ zeroIsError));
11019
11015
11020
11016
if (strcmp(typcategory, "U") != 0)
11021
11017
{
@@ -11818,7 +11814,7 @@ format_function_arguments_old(Archive *fout,
11818
11814
for (j = 0; j < nallargs; j++)
11819
11815
{
11820
11816
Oid typid;
11821
- char *typname;
11817
+ const char *typname;
11822
11818
const char *argmode;
11823
11819
const char *argname;
11824
11820
@@ -11857,7 +11853,6 @@ format_function_arguments_old(Archive *fout,
11857
11853
argname ? fmtId(argname) : "",
11858
11854
argname ? " " : "",
11859
11855
typname);
11860
- free(typname);
11861
11856
}
11862
11857
appendPQExpBufferChar(&fn, ')');
11863
11858
return fn.data;
@@ -11886,15 +11881,12 @@ format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
11886
11881
appendPQExpBuffer(&fn, "%s(", finfo->dobj.name);
11887
11882
for (j = 0; j < finfo->nargs; j++)
11888
11883
{
11889
- char *typname;
11890
-
11891
11884
if (j > 0)
11892
11885
appendPQExpBufferStr(&fn, ", ");
11893
11886
11894
- typname = getFormattedTypeName(fout, finfo->argtypes[j],
11895
- zeroIsError);
11896
- appendPQExpBufferStr(&fn, typname);
11897
- free(typname);
11887
+ appendPQExpBufferStr(&fn,
11888
+ getFormattedTypeName(fout, finfo->argtypes[j],
11889
+ zeroIsError));
11898
11890
}
11899
11891
appendPQExpBufferChar(&fn, ')');
11900
11892
return fn.data;
@@ -11938,7 +11930,6 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
11938
11930
char *prosupport;
11939
11931
char *proparallel;
11940
11932
char *lanname;
11941
- char *rettypename;
11942
11933
int nallargs;
11943
11934
char **allargtypes = NULL;
11944
11935
char **argmodes = NULL;
@@ -12295,14 +12286,10 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
12295
12286
else if (funcresult)
12296
12287
appendPQExpBuffer(q, " RETURNS %s", funcresult);
12297
12288
else
12298
- {
12299
- rettypename = getFormattedTypeName(fout, finfo->prorettype,
12300
- zeroIsError);
12301
12289
appendPQExpBuffer(q, " RETURNS %s%s",
12302
12290
(proretset[0] == 't') ? "SETOF " : "",
12303
- rettypename);
12304
- free(rettypename);
12305
- }
12291
+ getFormattedTypeName(fout, finfo->prorettype,
12292
+ zeroIsError));
12306
12293
12307
12294
appendPQExpBuffer(q, "\n LANGUAGE %s", fmtId(lanname));
12308
12295
@@ -12509,8 +12496,8 @@ dumpCast(Archive *fout, CastInfo *cast)
12509
12496
PQExpBuffer labelq;
12510
12497
PQExpBuffer castargs;
12511
12498
FuncInfo *funcInfo = NULL;
12512
- char *sourceType;
12513
- char *targetType;
12499
+ const char *sourceType;
12500
+ const char *targetType;
12514
12501
12515
12502
/* Skip if not to be dumped */
12516
12503
if (!cast->dobj.dump || dopt->dataOnly)
@@ -12596,9 +12583,6 @@ dumpCast(Archive *fout, CastInfo *cast)
12596
12583
NULL, "",
12597
12584
cast->dobj.catId, 0, cast->dobj.dumpId);
12598
12585
12599
- free(sourceType);
12600
- free(targetType);
12601
-
12602
12586
destroyPQExpBuffer(defqry);
12603
12587
destroyPQExpBuffer(delqry);
12604
12588
destroyPQExpBuffer(labelq);
@@ -12619,7 +12603,7 @@ dumpTransform(Archive *fout, TransformInfo *transform)
12619
12603
FuncInfo *fromsqlFuncInfo = NULL;
12620
12604
FuncInfo *tosqlFuncInfo = NULL;
12621
12605
char *lanname;
12622
- char *transformType;
12606
+ const char *transformType;
12623
12607
12624
12608
/* Skip if not to be dumped */
12625
12609
if (!transform->dobj.dump || dopt->dataOnly)
@@ -12726,7 +12710,6 @@ dumpTransform(Archive *fout, TransformInfo *transform)
12726
12710
transform->dobj.catId, 0, transform->dobj.dumpId);
12727
12711
12728
12712
free(lanname);
12729
- free(transformType);
12730
12713
destroyPQExpBuffer(defqry);
12731
12714
destroyPQExpBuffer(delqry);
12732
12715
destroyPQExpBuffer(labelq);
@@ -14018,17 +14001,11 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
14018
14001
{
14019
14002
appendPQExpBufferChar(&buf, '(');
14020
14003
for (j = 0; j < agginfo->aggfn.nargs; j++)
14021
- {
14022
- char *typname;
14023
-
14024
- typname = getFormattedTypeName(fout, agginfo->aggfn.argtypes[j],
14025
- zeroIsError);
14026
-
14027
14004
appendPQExpBuffer(&buf, "%s%s",
14028
14005
(j > 0) ? ", " : "",
14029
- typname);
14030
- free(typname);
14031
- }
14006
+ getFormattedTypeName(fout,
14007
+ agginfo->aggfn.argtypes[j],
14008
+ zeroIsError));
14032
14009
appendPQExpBufferChar(&buf, ')');
14033
14010
}
14034
14011
return buf.data;
@@ -18728,8 +18705,10 @@ findDumpableDependencies(ArchiveHandle *AH, DumpableObject *dobj,
18728
18705
*
18729
18706
* This does not guarantee to schema-qualify the output, so it should not
18730
18707
* be used to create the target object name for CREATE or ALTER commands.
18708
+ *
18709
+ * Note that the result is cached and must not be freed by the caller.
18731
18710
*/
18732
- static char *
18711
+ static const char *
18733
18712
getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
18734
18713
{
18735
18714
TypeInfo *typeInfo;
@@ -18740,15 +18719,15 @@ getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
18740
18719
if (oid == 0)
18741
18720
{
18742
18721
if ((opts & zeroAsStar) != 0)
18743
- return pg_strdup( "*") ;
18722
+ return "*";
18744
18723
else if ((opts & zeroAsNone) != 0)
18745
- return pg_strdup( "NONE") ;
18724
+ return "NONE";
18746
18725
}
18747
18726
18748
18727
/* see if we have the result cached in the type's TypeInfo record */
18749
18728
typeInfo = findTypeByOid(oid);
18750
18729
if (typeInfo && typeInfo->ftypname)
18751
- return pg_strdup( typeInfo->ftypname) ;
18730
+ return typeInfo->ftypname;
18752
18731
18753
18732
query = createPQExpBuffer();
18754
18733
appendPQExpBuffer(query, "SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
@@ -18762,9 +18741,14 @@ getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
18762
18741
PQclear(res);
18763
18742
destroyPQExpBuffer(query);
18764
18743
18765
- /* cache a copy for later requests */
18744
+ /*
18745
+ * Cache the result for re-use in later requests, if possible. If we
18746
+ * don't have a TypeInfo for the type, the string will be leaked once the
18747
+ * caller is done with it ... but that case really should not happen, so
18748
+ * leaking if it does seems acceptable.
18749
+ */
18766
18750
if (typeInfo)
18767
- typeInfo->ftypname = pg_strdup( result) ;
18751
+ typeInfo->ftypname = result;
18768
18752
18769
18753
return result;
18770
18754
}
0 commit comments