Fix memory leak in print_modinfo reported by Coverity Report.
It seems there is a logic error and duplicated string in print_modinfo
is never freed. On top of this if the while loop terminates early the
just allocated duplicated string is also never freed.
Rework the function to correctly free the duplicated string.
Fix CID
1586644: Resource leaks (RESOURCE_LEAK).
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
printf("%s:\t%s\n", dup, sep);
} else {
sep2 = strstr(sep, ":");
- if (!sep2)
+ if (!sep2) {
+ free(dup);
break;
+ }
+
pname = strndup(sep, sep2 - sep);
sep2++;
pdata = strdup(sep2);
else
p->desc = pdata;
}
+
+ free(dup);
next_string:
strings = &sep[strlen(sep)];
- if (dup)
- free(dup);
}
list_for_each_entry(p, ¶ms, list) {