]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
fix(dracut-install): release memory allocated for regular expressions
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Tue, 28 Nov 2023 14:43:41 +0000 (15:43 +0100)
committerLaszlo Gombos <laszlo.gombos@gmail.com>
Wed, 17 Apr 2024 15:43:49 +0000 (11:43 -0400)
Use `regfree` to free memory allocated by `regcomp`. Quoting [1]:

"If the preg argument to regexec() or regfree() is not a compiled regular
expression returned by regcomp(), the result is undefined."

Therefore, `regfree` must only be called if `regcomp` succeeded.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/regcomp.html

src/install/dracut-install.c

index 7473e87af2c26aa855920452cd236058c6ab3ec0..446ba959769c2376858fc01741b55d93fdaa5817 100644 (file)
@@ -2275,6 +2275,17 @@ finish2:
         hashmap_free(modules_suppliers);
         hashmap_free(processed_suppliers);
 
+        if (arg_mod_filter_path)
+                regfree(&mod_filter_path);
+        if (arg_mod_filter_nopath)
+                regfree(&mod_filter_nopath);
+        if (arg_mod_filter_symbol)
+                regfree(&mod_filter_symbol);
+        if (arg_mod_filter_nosymbol)
+                regfree(&mod_filter_nosymbol);
+        if (arg_mod_filter_noname)
+                regfree(&mod_filter_noname);
+
         strv_free(firmwaredirs);
         strv_free(pathdirs);
         return r;