Re: [PATCH 5/6] Fix memory leak in securityselinuxlabeltest.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 01/13/2014 11:12 AM, Pavel Hrdina wrote:
> Strings "file" and "context" may not be freed if "VIR_EXPAND_N" fails
> and it leads into memory leak.
> 
> This has been found by coverity.
> 
> Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
> ---
>  tests/securityselinuxlabeltest.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
> index d1fd92f..08b2997 100644
> --- a/tests/securityselinuxlabeltest.c
> +++ b/tests/securityselinuxlabeltest.c
> @@ -127,8 +127,11 @@ testSELinuxLoadFileList(const char *testname,
>              context = NULL;
>          }

When 'file' is declared above, you'll need to add a 'file = NULL'...
Probably could do the same for context, thus removing the need for the
context = NULL else condition.

ACK with the adjustments

John
>  
> -        if (VIR_EXPAND_N(*files, *nfiles, 1) < 0)
> +        if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) {
> +            VIR_FREE(file);
> +            VIR_FREE(context);
>              goto cleanup;
> +        }
>  
>          (*files)[(*nfiles)-1].file = file;
>          (*files)[(*nfiles)-1].context = context;
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]