Commit 1db76ab588bf1a976b1aebb8fb5bdbec3e718b69

Martin Pieuchot 2018-01-26T14:26:35

Some memory failure checks were missing.

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;