]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: Remove a malloc call
authorEmil Velikov <emil.l.velikov@gmail.com>
Thu, 17 Oct 2024 13:53:03 +0000 (15:53 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Wed, 13 Nov 2024 14:56:11 +0000 (08:56 -0600)
The offsets of node children can be stored on stack.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/188
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/depmod.c

index 435917c040fe9a0f48e1d2d25c599eead3437c78..822b8dbd3c2f54e48b04719a5bbffddce6795dc1 100644 (file)
@@ -384,7 +384,7 @@ static uint32_t index_calculate_size(struct index_node *node)
 static uint32_t index_write__node(const struct index_node *node, FILE *out,
                                  uint32_t offset)
 {
-       uint32_t *child_offs = NULL;
+       uint32_t child_offs[INDEX_CHILDMAX] = {};
        int child_count = 0;
 
        /* Calculate children offsets */
@@ -393,9 +393,6 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out,
                size_t sizes = 0;
 
                child_count = node->last - node->first + 1;
-               child_offs = malloc(child_count * sizeof(uint32_t));
-               if (child_offs == NULL)
-                       fatal_oom();
 
                for (i = 0; i < child_count; i++) {
                        struct index_node *child;
@@ -424,8 +421,6 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out,
                fwrite(child_offs, sizeof(uint32_t), child_count, out);
        }
 
-       free(child_offs);
-
        if (node->values) {
                const struct index_value *v;
                unsigned int value_count;