Some memory failure checks were missing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/lib/object.c b/lib/object.c
index 6b3f9d5..0405a33 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -203,6 +203,8 @@ parse_object_header(struct got_object **obj, char *buf, size_t len)
return got_error(GOT_ERR_BAD_OBJ_HDR);
*obj = calloc(1, sizeof(**obj));
+ if (*obj == NULL)
+ return got_error(GOT_ERR_NO_MEM);
(*obj)->type = type;
(*obj)->hdrlen = hdrlen;
(*obj)->size = size;
diff --git a/lib/refs.c b/lib/refs.c
index a754c23..9392f66 100644
--- a/lib/refs.c
+++ b/lib/refs.c
@@ -53,6 +53,8 @@ parse_symref(struct got_reference **ref, const char *name, const char *line)
}
*ref = calloc(1, sizeof(**ref));
+ if (*ref == NULL)
+ return got_error(GOT_ERR_NO_MEM);
(*ref)->flags |= GOT_REF_IS_SYMBOLIC;
symref = &((*ref)->ref.symref);
symref->name = symref_name;
@@ -79,6 +81,8 @@ parse_ref_line(struct got_reference **ref, const char *name, const char *line)
return got_error(GOT_ERR_NOT_REF);
*ref = calloc(1, sizeof(**ref));
+ if (*ref == NULL)
+ return got_error(GOT_ERR_NO_MEM);
(*ref)->ref.ref.name = ref_name;
memcpy(&(*ref)->ref.ref.sha1, digest, SHA1_DIGEST_LENGTH);
return NULL;
@@ -172,10 +176,11 @@ got_ref_close(struct got_reference *ref)
struct got_reference *
got_ref_dup(struct got_reference *ref)
{
- struct got_reference *ret = calloc(1, sizeof(*ret));
+ struct got_reference *ret;
char *name = NULL;
char *symref = NULL;
+ ret = calloc(1, sizeof(*ret));
if (ret == NULL)
return NULL;