Re: [LTP] [PATCH]: Fix memory leak by freeing buf

Alexey Kodanev
2015-06-19T12:17:42Z

On 06/19/2015 03:09 PM, Alexey Kodanev wrote:
> Hi!
> On 06/19/2015 02:25 PM, Manjeet Pawar wrote:
>> From: Manjeet Pawar <manjeet.p@samsung.com>
>> Date: Fri, 19 Jun 2015 16:45:54 +0530
>> Subject: [PATCH] testcases/open_posix_testsuite/functional/semaphores: Fix memory leak by freeing buf
>>
>> This patch fix memory leak by freeing memory leak before function return
>>
>> Signed-off-by: Manjeet Pawar <manjeet.p@samsung.com>
>> Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com>
>> ---
>> .../functional/semaphores/sem_conpro.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c b/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
>> index f5f1abf..f3a4cfb 100644
>> --- a/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
>> +++ b/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
>> @@ -106,19 +106,23 @@ int main(int argc, char *argv[])
>>
>> #ifndef _POSIX_SEMAPHORES
>> printf("_POSIX_SEMAPHORES is not defined \n");
>> + free(buf);
>> return PTS_UNRESOLVED;
>> #endif
>> if (-1 == sem_init(&(buf->occupied), shared, occupied_value)) {
>> perror("sem_init didn't return success \n");
>> printf("hello \n");

Also, do you know why it prints "hello"? It should be removed I guess.

Thanks,
Alexey