diff mbox series

libselinux: free memory in error branch

Message ID 20220510174551.24679-1-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit 8266fd9401b9
Headers show
Series libselinux: free memory in error branch | expand

Commit Message

Christian Göttsche May 10, 2022, 5:45 p.m. UTC
In case the allocation for the filename fails, free the memory of the context.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/src/selinux_restorecon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

James Carter May 11, 2022, 8:42 p.m. UTC | #1
On Tue, May 10, 2022 at 5:02 PM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> In case the allocation for the filename fails, free the memory of the context.
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  libselinux/src/selinux_restorecon.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> index e6192912..e160c06e 100644
> --- a/libselinux/src/selinux_restorecon.c
> +++ b/libselinux/src/selinux_restorecon.c
> @@ -489,13 +489,15 @@ static int filespec_add(ino_t ino, const char *con, const char *file,
>                 goto oom_freefl;
>         fl->file = strdup(file);
>         if (!fl->file)
> -               goto oom_freefl;
> +               goto oom_freeflcon;
>         fl->next = prevfl->next;
>         prevfl->next = fl;
>
>         __pthread_mutex_unlock(&fl_mutex);
>         return 0;
>
> +oom_freeflcon:
> +       free(fl->con);
>  oom_freefl:
>         free(fl);
>  oom:
> --
> 2.36.1
>
James Carter May 16, 2022, 5:13 p.m. UTC | #2
On Wed, May 11, 2022 at 4:42 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Tue, May 10, 2022 at 5:02 PM Christian Göttsche
> <cgzones@googlemail.com> wrote:
> >
> > In case the allocation for the filename fails, free the memory of the context.
> >
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
>

Merged.
Thanks,
Jim

> > ---
> >  libselinux/src/selinux_restorecon.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
> > index e6192912..e160c06e 100644
> > --- a/libselinux/src/selinux_restorecon.c
> > +++ b/libselinux/src/selinux_restorecon.c
> > @@ -489,13 +489,15 @@ static int filespec_add(ino_t ino, const char *con, const char *file,
> >                 goto oom_freefl;
> >         fl->file = strdup(file);
> >         if (!fl->file)
> > -               goto oom_freefl;
> > +               goto oom_freeflcon;
> >         fl->next = prevfl->next;
> >         prevfl->next = fl;
> >
> >         __pthread_mutex_unlock(&fl_mutex);
> >         return 0;
> >
> > +oom_freeflcon:
> > +       free(fl->con);
> >  oom_freefl:
> >         free(fl);
> >  oom:
> > --
> > 2.36.1
> >
diff mbox series

Patch

diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
index e6192912..e160c06e 100644
--- a/libselinux/src/selinux_restorecon.c
+++ b/libselinux/src/selinux_restorecon.c
@@ -489,13 +489,15 @@  static int filespec_add(ino_t ino, const char *con, const char *file,
 		goto oom_freefl;
 	fl->file = strdup(file);
 	if (!fl->file)
-		goto oom_freefl;
+		goto oom_freeflcon;
 	fl->next = prevfl->next;
 	prevfl->next = fl;
 
 	__pthread_mutex_unlock(&fl_mutex);
 	return 0;
 
+oom_freeflcon:
+	free(fl->con);
 oom_freefl:
 	free(fl);
 oom: