diff mbox

[2/2] sestatus: free process and file contexts which are checked

Message ID 20180422192148.7320-2-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss April 22, 2018, 7:21 p.m. UTC
clang's static analyzer reports a potential memory leak because the
buffers allocated in pc and fc are not freed in main(), in sestatus.c.
Free these buffers properly.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 policycoreutils/sestatus/sestatus.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

William Roberts April 23, 2018, 4:54 p.m. UTC | #1
On Sun, Apr 22, 2018 at 12:21 PM, Nicolas Iooss <nicolas.iooss@m4x.org> wrote:
> clang's static analyzer reports a potential memory leak because the
> buffers allocated in pc and fc are not freed in main(), in sestatus.c.
> Free these buffers properly.
>
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> ---
>  policycoreutils/sestatus/sestatus.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/policycoreutils/sestatus/sestatus.c b/policycoreutils/sestatus/sestatus.c
> index d7f198c2fa0d..9a92e72ff4fd 100644
> --- a/policycoreutils/sestatus/sestatus.c
> +++ b/policycoreutils/sestatus/sestatus.c
> @@ -436,6 +436,7 @@ int main(int argc, char **argv)
>                         printf("%s\n", context);
>                         freecon(context);
>                 }
> +               free(pc[i]);
>         }
>
>         printf("\nFile contexts:\n");
> @@ -478,6 +479,7 @@ int main(int argc, char **argv)
>                                 freecon(context);
>                         }
>                 }
> +               free(fc[i]);
>         }
>
>         return 0;
> --
> 2.17.0
>
>
ack on both patches in this series.
William Roberts April 25, 2018, 5:09 p.m. UTC | #2
Merged: https://github.com/SELinuxProject/selinux/pull/94

On Mon, Apr 23, 2018 at 9:54 AM, William Roberts
<bill.c.roberts@gmail.com> wrote:
> On Sun, Apr 22, 2018 at 12:21 PM, Nicolas Iooss <nicolas.iooss@m4x.org> wrote:
>> clang's static analyzer reports a potential memory leak because the
>> buffers allocated in pc and fc are not freed in main(), in sestatus.c.
>> Free these buffers properly.
>>
>> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
>> ---
>>  policycoreutils/sestatus/sestatus.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/policycoreutils/sestatus/sestatus.c b/policycoreutils/sestatus/sestatus.c
>> index d7f198c2fa0d..9a92e72ff4fd 100644
>> --- a/policycoreutils/sestatus/sestatus.c
>> +++ b/policycoreutils/sestatus/sestatus.c
>> @@ -436,6 +436,7 @@ int main(int argc, char **argv)
>>                         printf("%s\n", context);
>>                         freecon(context);
>>                 }
>> +               free(pc[i]);
>>         }
>>
>>         printf("\nFile contexts:\n");
>> @@ -478,6 +479,7 @@ int main(int argc, char **argv)
>>                                 freecon(context);
>>                         }
>>                 }
>> +               free(fc[i]);
>>         }
>>
>>         return 0;
>> --
>> 2.17.0
>>
>>
> ack on both patches in this series.
diff mbox

Patch

diff --git a/policycoreutils/sestatus/sestatus.c b/policycoreutils/sestatus/sestatus.c
index d7f198c2fa0d..9a92e72ff4fd 100644
--- a/policycoreutils/sestatus/sestatus.c
+++ b/policycoreutils/sestatus/sestatus.c
@@ -436,6 +436,7 @@  int main(int argc, char **argv)
 			printf("%s\n", context);
 			freecon(context);
 		}
+		free(pc[i]);
 	}
 
 	printf("\nFile contexts:\n");
@@ -478,6 +479,7 @@  int main(int argc, char **argv)
 				freecon(context);
 			}
 		}
+		free(fc[i]);
 	}
 
 	return 0;