Skip to contentSkip to conversation

libselinux: free memory in error branch

PATCH In review Christian Göttsche 2 participants 3 messages May 10, 2022 – May 16, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: free memory in error branch

In case the allocation for the filename fails, free the memory of the context.

---
 libselinux/src/selinux_restorecon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libselinux/src/selinux_restorecon.c +3 -1
index e6192912..e160c06e 100644
@@ -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:
Signature · 1 line
2.36.1
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Christian Göttsche

In case the allocation for the filename fails, free the memory of the context.

Quoted 28 lines
---
 libselinux/src/selinux_restorecon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libselinux/src/selinux_restorecon.c +3 -2
index e6192912..e160c06e 100644
@@ -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

#2 lore raw
Quoted 10 lines · James Carter
Quoted 4 lines · Christian Göttsche

In case the allocation for the filename fails, free the memory of the context.

Merged.
Thanks,
Jim

Quoted 28 lines
Quoted 28 lines
---
 libselinux/src/selinux_restorecon.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libselinux/src/selinux_restorecon.c +3 -2
index e6192912..e160c06e 100644
@@ -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