From a8e1a698299aaed73e75dc72286c1dd15a202765 Mon Sep 17 00:00:00 2001 From: xfnw Date: Thu, 30 Jun 2022 19:12:31 -0400 Subject: [PATCH] fix memory leak on realloc falure --- stagit.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stagit.c b/stagit.c index 2ff6251..401e2cd 100644 --- a/stagit.c +++ b/stagit.c @@ -324,8 +324,14 @@ getrefs(struct referenceinfo **pris, size_t *prefcount) if (!(ci = commitinfo_getbyoid(id))) break; - if (!(ris = reallocarray(ris, refcount + 1, sizeof(*ris)))) - err(1, "realloc"); + { + struct referenceinfo *newris; + if (!(newris = reallocarray(ris, refcount + 1, sizeof(*ris)))) { + free(ris); + err(1, "realloc"); + } + ris = newris; + } ris[refcount].ci = ci; ris[refcount].ref = r; refcount++;