summaryrefslogtreecommitdiff
path: root/src/common/parse_manifest.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2024-04-09 09:07:14 -0400
committerAndrew Dunstan <andrew@dunslane.net>2024-04-12 10:32:30 -0400
commit661ab4e185784db79c194b5758555b1db3f30483 (patch)
treec5fdde1cecca9ea8440f5e8e2412741acc34d580 /src/common/parse_manifest.c
parentb9ecefecc7aaad117e0255b56b759f524f0f4363 (diff)
Fix some memory leaks associated with parsing json and manifests
Coverity complained about not freeing some memory associated with incrementally parsing backup manifests. To fix that, provide and use a new shutdown function for the JsonManifestParseIncrementalState object, in line with a suggestion from Tom Lane. While analysing the problem, I noticed a buglet in freeing memory for incremental json lexers. To fix that remove a bogus condition on freeing the memory allocated for them.
Diffstat (limited to 'src/common/parse_manifest.c')
-rw-r--r--src/common/parse_manifest.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/common/parse_manifest.c b/src/common/parse_manifest.c
index 970a756ce8a..a94e3d6b154 100644
--- a/src/common/parse_manifest.c
+++ b/src/common/parse_manifest.c
@@ -123,7 +123,6 @@ static bool parse_xlogrecptr(XLogRecPtr *result, char *input);
/*
* Set up for incremental parsing of the manifest.
- *
*/
JsonManifestParseIncrementalState *
@@ -164,6 +163,18 @@ json_parse_manifest_incremental_init(JsonManifestParseContext *context)
}
/*
+ * Free an incremental state object and its contents.
+ */
+void
+json_parse_manifest_incremental_shutdown(JsonManifestParseIncrementalState *incstate)
+{
+ pfree(incstate->sem.semstate);
+ freeJsonLexContext(&(incstate->lex));
+ /* incstate->manifest_ctx has already been freed */
+ pfree(incstate);
+}
+
+/*
* parse the manifest in pieces.
*
* The caller must ensure that the final piece contains the final lines