add_commit_patch_id(): avoid allocating memory unnecessarily

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed May 4, 2017 at 15:55 UTC 5748693b9123f55363211d18e8074db5e1b8384e
1 file changed +2 -1
patch-ids.c
+2 -1
@@ -99,11 +99,12 @@ struct patch_id *has_commit_patch_id(struct commit *commit,
99 struct patch_id *add_commit_patch_id(struct commit *commit,
100 struct patch_ids *ids)
101 {
102 - struct patch_id *key = xcalloc(1, sizeof(*key));
102 + struct patch_id *key;
103
104 if (!patch_id_defined(commit))
105 return NULL;
106
107 + key = xcalloc(1, sizeof(*key));
108 if (init_patch_id_entry(key, commit, ids)) {
109 free(key);
110 return NULL;