Skip to content

Commit 353708e

Browse files
committed
Clean up recent Coverity complaints.
Commit 5c649fe introduced a memory leak into pg_basebackup's parse_compress_options. (I simplified nearby code while at it.) Commit 9a974cb 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 b89e151; I suppose the reason it showed up now is 7a5f6b4's recent rearrangement of nearby code.)
1 parent dc43fc9 commit 353708e

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/backend/replication/logical/decode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ heap_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
498498
if (!TransactionIdIsValid(xid))
499499
break;
500500

501-
SnapBuildProcessChange(builder, xid, buf->origptr);
501+
(void) SnapBuildProcessChange(builder, xid, buf->origptr);
502502
ReorderBufferXidSetCatalogChanges(ctx->reorder, xid, buf->origptr);
503503
break;
504504

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
948948
{
949949
char *sep;
950950
int firstlen;
951-
char *firstpart = NULL;
951+
char *firstpart;
952952

953953
/* check if the option is split in two */
954954
sep = strchr(src, ':');
@@ -959,7 +959,7 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
959959
*/
960960
firstlen = (sep != NULL) ? (sep - src) : strlen(src);
961961
firstpart = pg_malloc(firstlen + 1);
962-
strncpy(firstpart, src, firstlen);
962+
memcpy(firstpart, src, firstlen);
963963
firstpart[firstlen] = '\0';
964964

965965
/*
@@ -983,6 +983,8 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
983983

984984
*methodres = (*levelres > 0) ?
985985
COMPRESSION_GZIP : COMPRESSION_NONE;
986+
987+
free(firstpart);
986988
return;
987989
}
988990

@@ -992,6 +994,7 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
992994
* The caller specified a method without a colon separator, so let any
993995
* subsequent checks assign a default level.
994996
*/
997+
free(firstpart);
995998
return;
996999
}
9971000

@@ -1010,6 +1013,8 @@ parse_compress_options(char *src, WalCompressionMethod *methodres,
10101013
if (!option_parse_int(sep, "-Z/--compress", 0, INT_MAX,
10111014
levelres))
10121015
exit(1);
1016+
1017+
free(firstpart);
10131018
}
10141019

10151020
/*

src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4714,7 +4714,6 @@ binary_upgrade_set_pg_class_oids(Archive *fout,
47144714
}
47154715

47164716
PQclear(upgrade_res);
4717-
destroyPQExpBuffer(upgrade_query);
47184717
}
47194718
else
47204719
{
@@ -4728,6 +4727,8 @@ binary_upgrade_set_pg_class_oids(Archive *fout,
47284727
}
47294728

47304729
appendPQExpBufferChar(upgrade_buffer, '\n');
4730+
4731+
destroyPQExpBuffer(upgrade_query);
47314732
}
47324733

47334734
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy