]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: replace malloc with xmalloc
authorSiddharth Shrimali <r.siddharth.shrimali@gmail.com>
Tue, 10 Mar 2026 16:44:12 +0000 (22:14 +0530)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Mar 2026 18:17:56 +0000 (11:17 -0700)
The submodule_summary_callback() function currently uses a raw malloc()
which could lead to a NULL pointer dereference.

Standardize this by replacing malloc() with xmalloc() for error handling.
To improve maintainability, use sizeof(*temp) instead of the struct name,
and drop the typecast of void pointer assignment.

Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c

index d537ab087a02e92916da62fd9360e64921a18f40..20dd9d04b664f223a9fe8ce90fe71e4d067774e3 100644 (file)
@@ -1059,7 +1059,7 @@ static void submodule_summary_callback(struct diff_queue_struct *q,
 
                if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
                        continue;
-               temp = (struct module_cb*)malloc(sizeof(struct module_cb));
+               temp = xmalloc(sizeof(*temp));
                temp->mod_src = p->one->mode;
                temp->mod_dst = p->two->mode;
                temp->oid_src = p->one->oid;