fix memory leak on realloc falure

This commit is contained in:
xfnw 2022-06-30 19:12:31 -04:00
parent 271b68a1b5
commit a8e1a69829
1 changed files with 8 additions and 2 deletions

View File

@ -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++;