Commit Diff


commit - a0b3389c1fd0410d5840649d7646db956a3f7815
commit + 5df4932d8e7905f8e04dbf16e3879da18a091cec
blob - bd8091df251a7ee59403fe2a6d5ae2b91e4de099
blob + f6669fd0b9bea0a21d77886b9e2933fc07952a79
--- lib/commit_graph.c
+++ lib/commit_graph.c
@@ -244,18 +244,12 @@ add_node_to_iter_list(struct got_commit_graph *graph,
 static const struct got_error *
 add_vertex(struct got_object_id_queue *ids, struct got_object_id *id)
 {
+	const struct got_error *err = NULL;
 	struct got_object_qid *qid;
 
-	qid = calloc(1, sizeof(*qid));
-	if (qid == NULL)
-		return got_error_from_errno();
-
-	qid->id = got_object_id_dup(id);
-	if (qid->id == NULL) {
-		const struct got_error *err = got_error_from_errno();
-		got_object_qid_free(qid);
+	err = got_object_qid_alloc(&qid, id);
+	if (err)
 		return err;
-	}
 
 	SIMPLEQ_INSERT_TAIL(ids, qid, entry);
 	return NULL;
blob - b427544ee597fb40d4802b61166507af2c7f124e
blob + f53705294442da0455ee9f988a17bdd3966aaf58
--- lib/got_lib_object_parse.h
+++ lib/got_lib_object_parse.h
@@ -14,6 +14,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+const struct got_error *got_object_qid_alloc_partial(struct got_object_qid **);
 struct got_commit_object *got_object_commit_alloc_partial(void);
 struct got_tree_entry *got_alloc_tree_entry_partial(void);
 const struct got_error *got_object_read_header_privsep(struct got_object**,
blob - 46c648c9817c637977cca2543e256910f3c92de3
blob + ebec64016f1700fa3992736a847eea0e5816697f
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -63,6 +63,26 @@
 #define GOT_COMMIT_TAG_COMMITTER	"committer "
 
 const struct got_error *
+got_object_qid_alloc_partial(struct got_object_qid **qid)
+{
+	const struct got_error *err = NULL;
+
+	*qid = malloc(sizeof(**qid));
+	if (*qid == NULL)
+		return got_error_from_errno();
+
+	(*qid)->id = malloc(sizeof(*((*qid)->id)));
+	if ((*qid)->id == NULL) {
+		err = got_error_from_errno();
+		got_object_qid_free(*qid);
+		*qid = NULL;
+		return err;
+	}
+
+	return NULL;
+}
+
+const struct got_error *
 got_object_id_str(char **outbuf, struct got_object_id *id)
 {
 	static const size_t len = SHA1_DIGEST_STRING_LENGTH;
@@ -135,16 +155,9 @@ got_object_commit_add_parent(struct got_commit_object 
 	const struct got_error *err = NULL;
 	struct got_object_qid *qid;
 
-	qid = malloc(sizeof(*qid));
-	if (qid == NULL)
-		return got_error_from_errno();
-
-	qid->id = malloc(sizeof(*qid->id));
-	if (qid->id == NULL) {
-		err = got_error_from_errno();
-		got_object_qid_free(qid);
+	err = got_object_qid_alloc_partial(&qid);
+	if (err)
 		return err;
-	}
 
 	if (!got_parse_sha1_digest(qid->id->sha1, id_str)) {
 		err = got_error(GOT_ERR_BAD_OBJ_DATA);
blob - 9f128d5fc8571f4f80b51a0e7d17cd5bd4c739a8
blob + eac5aa1f667f6392bff2b7f4a6942ed60fa6b52f
--- lib/privsep.c
+++ lib/privsep.c
@@ -592,18 +592,9 @@ got_privsep_recv_commit(struct got_commit_object **com
 		for (i = 0; i < icommit.nparents; i++) {
 			struct got_object_qid *qid;
 
-			qid = calloc(1, sizeof(*qid));
-			if (qid == NULL) {
-				err = got_error_from_errno();
-				break;
-			}
-			qid->id = calloc(1, sizeof(*qid->id));
-			if (qid->id == NULL) {
-				err = got_error_from_errno();
-				free(qid);
+			err = got_object_qid_alloc_partial(&qid);
+			if (err)
 				break;
-			}
-
 			memcpy(qid->id, data + len + i * SHA1_DIGEST_LENGTH,
 			    sizeof(*qid->id));
 			SIMPLEQ_INSERT_TAIL(&(*commit)->parent_ids, qid, entry);