[PATCH v1] modprobe: Fix memory leak

Denys Vlasenko vda.linux at googlemail.com
Sun Jan 3 03:10:58 UTC 2021


Let's not do this, saving code size:
modprobe is not a long-running program.

On Tue, Dec 22, 2020 at 3:12 PM Andy Shevchenko
<andriy.shevchenko at linux.intel.com> wrote:
> Free command line options after parsing.
>
> Fixes: e4202df0918e ("modprobe: Add support for modprobe.blacklist=module1,module2,...")
> Reported-by: Denys Vlasenko <vda.linux at googlemail.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
> ---
>  modutils/modprobe.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/modutils/modprobe.c b/modutils/modprobe.c
> index c334186b831a..9aaf848cbd3e 100644
> --- a/modutils/modprobe.c
> +++ b/modutils/modprobe.c
> @@ -665,11 +665,11 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
>
>         /* Handle modprobe.blacklist=module1,module2,... */
>         if (ENABLE_FEATURE_MODPROBE_BLACKLIST) {
> -               char *options;
> +               char *options, *o;
>                 char *substr;
>
> -               options = parse_and_add_kcmdline_module_options(NULL, "modprobe");
> -               while ((substr = strsep(&options, " ")) != NULL) {
> +               options = o = parse_and_add_kcmdline_module_options(NULL, "modprobe");
> +               while ((substr = strsep(&o, " ")) != NULL) {
>                         char *fn = is_prefixed_with(substr, "blacklist=");
>                         if (!fn)
>                                 continue;
> @@ -679,7 +679,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
>                                 DBG("blacklist: %s", substr);
>                         }
>                 }
> -               /*free(options); - WRONG, strsep may have advanced it */
> +               free(options);
>         }
>
>         rc = 0;
> --
> 2.29.2
>


More information about the busybox mailing list