]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: fix leak in case of malloc(0)
authorLucas De Marchi <lucas.demarchi@intel.com>
Thu, 26 Feb 2015 06:38:52 +0000 (03:38 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Thu, 26 Feb 2015 06:40:47 +0000 (03:40 -0300)
malloc(0) can return != NULL. We need to pass the pointer to free().
This happens if index__haschildren(node) returned true, but
child_count is set to 0.

tools/depmod.c

index afde322be19d54f4b5e010522e6697097933b84d..851af0cc9b099bc926040241affd5d7d52b7dde8 100644 (file)
@@ -367,10 +367,11 @@ static uint32_t index_write__node(const struct index_node *node, FILE *out)
                fputc(node->first, out);
                fputc(node->last, out);
                fwrite(child_offs, sizeof(uint32_t), child_count, out);
-               free(child_offs);
                offset |= INDEX_NODE_CHILDS;
        }
 
+       free(child_offs);
+
        if (node->values) {
                const struct index_value *v;
                unsigned int value_count;