[PATCH v3 04/25] add_commit_patch_id(): avoid allocating memory unnecessarily
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- May 2, 2017, 16:01 UTC
- Message-ID
- <71aa1c1c90057c59dc6f549b42778a500e908acf.1493740497.git.johannes.schindelin@gmx.de>
- In-Reply-To
- <cover.1493740497.git.johannes.schindelin@gmx.de>
It would appear that we allocate (and forget to release) memory if the patch ID is not even defined.
Reported by the Coverity tool.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- patch-ids.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/patch-ids.c b/patch-ids.c index fa8f11de826..92eba7a059e 100644 --- a/patch-ids.c +++ b/patch-ids.c @@ -99,11 +99,12 @@ struct patch_id *has_commit_patch_id(struct commit *commit, struct patch_id *add_commit_patch_id(struct commit *commit, struct patch_ids *ids) { - struct patch_id *key = xcalloc(1, sizeof(*key)); + struct patch_id *key; if (!patch_id_defined(commit)) return NULL; + key = xcalloc(1, sizeof(*key)); if (init_patch_id_entry(key, commit, ids)) { free(key); return NULL;
-- 2.12.2.windows.2.800.gede8f145e06