public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] sem_conpro: fix memory leak
@ 2015-06-23  1:02 Wei,Jiangang
  2015-06-23 10:06 ` Alexey Kodanev
  0 siblings, 1 reply; 5+ messages in thread
From: Wei,Jiangang @ 2015-06-23  1:02 UTC (permalink / raw)
  To: ltp-list

* If _POSIX_SEMAPHORES is not defined,
  It's no need to allocate buffer.
  so, allocate buffer after checking it.

* free the memory at the end of main().

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c b/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
index f5f1abf..58657f9 100644
--- a/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
+++ b/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
@@ -102,12 +102,12 @@ int main(int argc, char *argv[])
 	int lock_value = 1;
 	buf_t *buf;
 	pthread_t con, pro;
-	buf = malloc(sizeof(buf_t));
 
 #ifndef  _POSIX_SEMAPHORES
 	printf("_POSIX_SEMAPHORES is not defined \n");
 	return PTS_UNRESOLVED;
 #endif
+	buf = malloc(sizeof(buf_t));
 	if (-1 == sem_init(&(buf->occupied), shared, occupied_value)) {
 		perror("sem_init didn't return success \n");
 		printf("hello \n");
@@ -129,5 +129,6 @@ int main(int argc, char *argv[])
 	pthread_join(pro, NULL);
 	sem_destroy(&buf->occupied);
 	sem_destroy(&buf->empty);
+	free(buf);
 	return PTS_PASS;
 }
-- 
1.9.3


------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-25 13:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-23  1:02 [LTP] [PATCH] sem_conpro: fix memory leak Wei,Jiangang
2015-06-23 10:06 ` Alexey Kodanev
2015-06-24  3:37   ` Wei, Jiangang
2015-06-24  3:41   ` [LTP] [PATCH v2] sem_conpro: cleanup code Wei,Jiangang
2015-06-25 13:46     ` Alexey Kodanev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox