summaryrefslogtreecommitdiffstats
path: root/modalias.c
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@mandriva.com>2009-04-03 17:46:28 +0000
committerChristophe Fergeau <cfergeau@mandriva.com>2009-04-03 17:46:28 +0000
commita30eb33ddef01e39c044a33cd45af88292641406 (patch)
tree85db706414ecba4968d4f4a06ad2b66413dface7 /modalias.c
parent43c2513120e27392640e50ecca1519980fcda1b0 (diff)
downloadldetect-a30eb33ddef01e39c044a33cd45af88292641406.tar
ldetect-a30eb33ddef01e39c044a33cd45af88292641406.tar.gz
ldetect-a30eb33ddef01e39c044a33cd45af88292641406.tar.bz2
ldetect-a30eb33ddef01e39c044a33cd45af88292641406.tar.xz
ldetect-a30eb33ddef01e39c044a33cd45af88292641406.zip
Leak less memory returned from libmodprobe
Diffstat (limited to 'modalias.c')
-rw-r--r--modalias.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/modalias.c b/modalias.c
index 6df02f0..790e71e 100644
--- a/modalias.c
+++ b/modalias.c
@@ -14,6 +14,52 @@
static char *aliasdefault = NULL;
+static void free_aliases(struct module_alias *aliases) {
+ while (aliases->next) {
+ struct module_alias *next;
+ next = aliases->next;
+ free(aliases->module);
+ free(aliases);
+ aliases = next;
+ }
+ free(aliases);
+}
+
+static void free_options(struct module_options *modoptions) {
+ while (modoptions->next) {
+ struct module_options *next;
+ next = modoptions->next;
+ free(modoptions->modulename);
+ free(modoptions->options);
+ free(modoptions);
+ modoptions = next;
+ }
+ free(modoptions);
+}
+
+static void free_commands(struct module_command *commands) {
+ while (commands->next) {
+ struct module_command *next;
+ next = commands->next;
+ free(commands->modulename);
+ free(commands->command);
+ free(commands);
+ commands = next;
+ }
+ free(commands);
+}
+
+static void free_blacklist(struct module_blacklist *blacklist) {
+ while (blacklist->next) {
+ struct module_blacklist *next;
+ next = blacklist->next;
+ free(blacklist->modulename);
+ free(blacklist);
+ blacklist = next;
+ }
+ free(blacklist);
+}
+
static void set_default_alias_file(void) {
struct utsname rel_buf;
if (!aliasdefault) {
@@ -71,12 +117,19 @@ char *modalias_resolve_module(const char *modalias) {
}
free(dkms_file);
}
+ free_blacklist(blacklist);
+ free_commands(commands);
+ free_options(modoptions);
if (aliases) {
+ char *result;
// take the last one because we find eg: generic/ata_generic/sata_sil
- while (aliases->next)
- aliases = aliases->next;
+ struct module_alias *it = aliases;
+ while (it->next)
+ it = it->next;
- return strdup(aliases->module);
+ result = strdup(it->module);
+ free_aliases(aliases);
+ return result;
}
return NULL;