]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: Use memdup
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 27 Sep 2024 20:15:59 +0000 (22:15 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 1 Oct 2024 14:12:13 +0000 (09:12 -0500)
No need to clear newly allocated memory if source is copied into
destination directly.

Simplify code by using memdup from shared.

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

index e736cac4a192e43c95fc4051cafb19062d544321..619997303e493493b402df4f26d3bc0242cecc0a 100644 (file)
@@ -265,10 +265,9 @@ static int index_insert(struct index_node *node, const char *key, const char *va
                                struct index_node *n;
 
                                /* New child is copy of node with prefix[j+1..N] */
-                               n = calloc(1, sizeof(struct index_node));
+                               n = memdup(node, sizeof(struct index_node));
                                if (n == NULL)
                                        fatal_oom();
-                               memcpy(n, node, sizeof(struct index_node));
                                n->prefix = strdup(&prefix[j + 1]);
                                if (n->prefix == NULL)
                                        fatal_oom();