From: Emil Velikov Date: Thu, 17 Oct 2024 13:53:03 +0000 (+0200) Subject: depmod: Remove a malloc call X-Git-Tag: v34~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c24480dff5b77762197a64d5a177b506274f227;p=thirdparty%2Fkmod.git depmod: Remove a malloc call The offsets of node children can be stored on stack. Signed-off-by: Tobias Stoeckmann Link: https://github.com/kmod-project/kmod/pull/188 Signed-off-by: Lucas De Marchi --- diff --git a/tools/depmod.c b/tools/depmod.c index 435917c0..822b8dbd 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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;