Skip to content

Commit 9c73395

Browse files
Add fastpaths for when no objects are found
If there are no objects found, there is no reason to inspect the result columns and mallocing a zero-sized (which will be 1 byte in reality) heap buffer for it. Add a fast-path for immediately returning like how other object inspection functions are already doing it. Reviewed-by: Ranier Vilela <ranier.vf@gmail.com> Discussion: https://postgr.es/m/C2F05B3C-1414-45DD-AE09-6FEE4D0F89BD@yesql.se
1 parent 1a123e3 commit 9c73395

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4314,6 +4314,9 @@ getPublications(Archive *fout)
43144314

43154315
ntups = PQntuples(res);
43164316

4317+
if (ntups == 0)
4318+
goto cleanup;
4319+
43174320
i_tableoid = PQfnumber(res, "tableoid");
43184321
i_oid = PQfnumber(res, "oid");
43194322
i_pubname = PQfnumber(res, "pubname");
@@ -4352,6 +4355,8 @@ getPublications(Archive *fout)
43524355
/* Decide whether we want to dump it */
43534356
selectDumpableObject(&(pubinfo[i].dobj), fout);
43544357
}
4358+
4359+
cleanup:
43554360
PQclear(res);
43564361

43574362
destroyPQExpBuffer(query);
@@ -5817,7 +5822,7 @@ getExtensions(Archive *fout, int *numExtensions)
58175822
int ntups;
58185823
int i;
58195824
PQExpBuffer query;
5820-
ExtensionInfo *extinfo;
5825+
ExtensionInfo *extinfo = NULL;
58215826
int i_tableoid;
58225827
int i_oid;
58235828
int i_extname;
@@ -5837,6 +5842,8 @@ getExtensions(Archive *fout, int *numExtensions)
58375842
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
58385843

58395844
ntups = PQntuples(res);
5845+
if (ntups == 0)
5846+
goto cleanup;
58405847

58415848
extinfo = (ExtensionInfo *) pg_malloc(ntups * sizeof(ExtensionInfo));
58425849

@@ -5866,6 +5873,7 @@ getExtensions(Archive *fout, int *numExtensions)
58665873
selectDumpableExtension(&(extinfo[i]), dopt);
58675874
}
58685875

5876+
cleanup:
58695877
PQclear(res);
58705878
destroyPQExpBuffer(query);
58715879

0 commit comments

Comments
 (0)