fix memory leak on realloc falure
This commit is contained in:
parent
271b68a1b5
commit
a8e1a69829
1 changed files with 8 additions and 2 deletions
10
stagit.c
10
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++;
|
||||
|
|
Loading…
Reference in a new issue