Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Aug 2025 16:43:55 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Warner Losh <imp@freebsd.org>, src-committers@freebsd.org,  dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org
Subject:   Re: git: bc598959090d - main - autofs: Plug memory leak
Message-ID:  <CANCZdfrTraKU5T1hLVk4o0LUwZDmTfnA%2BmvQtQC-5YyH9z-Z2g@mail.gmail.com>
In-Reply-To: <aJgrxGXSXTfbB9tv@kib.kiev.ua>
References:  <202508100156.57A1uMoa022605@gitrepo.freebsd.org> <aJgrxGXSXTfbB9tv@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Aug 9, 2025 at 11:19=E2=80=AFPM Konstantin Belousov <kostikbel@gmai=
l.com> wrote:
>
> On Sun, Aug 10, 2025 at 01:56:22AM +0000, Warner Losh wrote:
> > The branch main has been updated by imp:
> >
> > URL: https://cgit.FreeBSD.org/src/commit/?id=3Dbc598959090d43aa0fc6b913=
55979016a9449041
> >
> > commit bc598959090d43aa0fc6b91355979016a9449041
> > Author:     Enji Cooper <ngie@FreeBSD.org>
> > AuthorDate: 2025-08-10 01:52:31 +0000
> > Commit:     Warner Losh <imp@FreeBSD.org>
> > CommitDate: 2025-08-10 01:54:42 +0000
> >
> >     autofs: Plug memory leak
> >
> >     Originally, this was an extra free, but ngie@ suggested this
> >     change. Since that's the whole thing, I've set her as the author fo=
r
> >     this ancient review instead of trix@juniper.net.
> >
> >     Sugggested by: ngie
> >     Differential Revision: https://reviews.freebsd.org/D10063
> >     Sponsored by:           Netflix
> > ---
> >  usr.sbin/autofs/common.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/usr.sbin/autofs/common.c b/usr.sbin/autofs/common.c
> > index 18756752876c..6b98214162ae 100644
> > --- a/usr.sbin/autofs/common.c
> > +++ b/usr.sbin/autofs/common.c
> > @@ -149,7 +149,7 @@ create_directory(const char *path)
> >               error =3D mkdir(partial, 0755);
> >               if (error !=3D 0 && errno !=3D EEXIST) {
> >                       log_warn("cannot create %s", partial);
> > -                     return;
> > +                     break;
> >               }
> >       }
> >
> Isn't there another leak, occuring when the first break in the loop is ta=
ken?
> Then the 'partial' duped string is not freed.

I think it's always leaked. checked_strdup allocates it, then concat
allocates a new string that's set to partial. So no matter what, we
should free it, no?

Eg
diff --git a/usr.sbin/autofs/common.c b/usr.sbin/autofs/common.c
index 6b98214162ae..2dd7c290cebc 100644
--- a/usr.sbin/autofs/common.c
+++ b/usr.sbin/autofs/common.c
@@ -153,6 +153,7 @@ create_directory(const char *path)
                }
        }

+       free(partial);
        free(tofree);
 }

Warner



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfrTraKU5T1hLVk4o0LUwZDmTfnA%2BmvQtQC-5YyH9z-Z2g>