Clean up recent Coverity complaints.

Commit 5c649fe15 introduced a memory leak into pg_basebackup's
parse_compress_options.  (I simplified nearby code while at it.)

Commit 9a974cbcb introduced a memory leak into pg_dump's
binary_upgrade_set_pg_class_oids.

Coverity also complained about a call of SnapBuildProcessChange that
ignored the result, unlike every other call of that function.  This
is evidently intentional, so add a (void) cast to indicate that.
(It's also old, dating to b89e15105; I suppose the reason it showed
up now is 7a5f6b474's recent rearrangement of nearby code.)
This commit is contained in:
Tom Lane 2022-01-23 12:51:38 -05:00
parent dc43fc9b3a
commit 353708e1fb
3 changed files with 10 additions and 4 deletions

View File

@ -498,7 +498,7 @@ heap_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
if (!TransactionIdIsValid(xid))
break;
SnapBuildProcessChange(builder, xid, buf->origptr);
(void) SnapBuildProcessChange(builder, xid, buf->origptr);
ReorderBufferXidSetCatalogChanges(ctx->reorder, xid, buf->origptr);
break;

View File

@ -948,7 +948,7 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
{
char *sep;
int firstlen;
char *firstpart = NULL;
char *firstpart;
/* check if the option is split in two */
sep = strchr(src, ':');
@ -959,7 +959,7 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
*/
firstlen = (sep != NULL) ? (sep - src) : strlen(src);
firstpart = pg_malloc(firstlen + 1);
strncpy(firstpart, src, firstlen);
memcpy(firstpart, src, firstlen);
firstpart[firstlen] = '\0';
/*
@ -983,6 +983,8 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
*methodres = (*levelres > 0) ?
COMPRESSION_GZIP : COMPRESSION_NONE;
free(firstpart);
return;
}
@ -992,6 +994,7 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
* The caller specified a method without a colon separator, so let any
* subsequent checks assign a default level.
*/
free(firstpart);
return;
}
@ -1010,6 +1013,8 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
if (!option_parse_int(sep, "-Z/--compress", 0, INT_MAX,
levelres))
exit(1);
free(firstpart);
}
/*

View File

@ -4714,7 +4714,6 @@ binary_upgrade_set_pg_class_oids(Archive *fout,
}
PQclear(upgrade_res);
destroyPQExpBuffer(upgrade_query);
}
else
{
@ -4728,6 +4727,8 @@ binary_upgrade_set_pg_class_oids(Archive *fout,
}
appendPQExpBufferChar(upgrade_buffer, '\n');
destroyPQExpBuffer(upgrade_query);
}
/*