commit - a0b3389c1fd0410d5840649d7646db956a3f7815
commit + 5df4932d8e7905f8e04dbf16e3879da18a091cec
blob - bd8091df251a7ee59403fe2a6d5ae2b91e4de099
blob + f6669fd0b9bea0a21d77886b9e2933fc07952a79
--- lib/commit_graph.c
+++ lib/commit_graph.c
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
* 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
#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;
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
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();
+ err = got_object_qid_alloc_partial(&qid);
+ if (err)
break;
- }
- qid->id = calloc(1, sizeof(*qid->id));
- if (qid->id == NULL) {
- err = got_error_from_errno();
- free(qid);
- break;
- }
-
memcpy(qid->id, data + len + i * SHA1_DIGEST_LENGTH,
sizeof(*qid->id));
SIMPLEQ_INSERT_TAIL(&(*commit)->parent_ids, qid, entry);