]> git.proxmox.com Git - libgit2.git/commitdiff
blame_git: check return value of `git__calloc`
authorPatrick Steinhardt <ps@pks.im>
Tue, 28 Mar 2017 07:15:53 +0000 (09:15 +0200)
committerPatrick Steinhardt <ps@pks.im>
Tue, 4 Apr 2017 09:58:46 +0000 (11:58 +0200)
We do not check the return value of `git__calloc`, which may return
`NULL` in out-of-memory situations. Fix the error by using
`GITERR_CHECK_ALLOC`.

src/blame_git.c

index 6d2f1531f00b458aa2b04a6fcfd7230eac72665e..13f5cb47c1b4ba804adb6f83cbd6df9cb1161edf 100644 (file)
@@ -517,11 +517,12 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
        if (!num_parents) {
                git_oid_cpy(&blame->options.oldest_commit, git_commit_id(commit));
                goto finish;
-       }
-       else if (num_parents < (int)ARRAY_SIZE(sg_buf))
+       } else if (num_parents < (int)ARRAY_SIZE(sg_buf))
                memset(sg_buf, 0, sizeof(sg_buf));
-       else
+       else {
                sg_origin = git__calloc(num_parents, sizeof(*sg_origin));
+               GITERR_CHECK_ALLOC(sg_origin);
+       }
 
        for (i=0; i<num_parents; i++) {
                git_commit *p;