All of lore.kernel.org
 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

* Re: [LTP] [PATCH] sem_conpro: fix memory leak
  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
  0 siblings, 2 replies; 5+ messages in thread
From: Alexey Kodanev @ 2015-06-23 10:06 UTC (permalink / raw)
  To: Wei, Jiangang, ltp-list

Hi!
On 06/23/2015 04:02 AM, Wei,Jiangang wrote:
> * 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(-)

Please look at "[LTP] [PATCH]: Fix memory leak by freeing buf" thread.

Thanks,
Alexey


------------------------------------------------------------------------------
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	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH] sem_conpro: fix memory leak
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Wei, Jiangang @ 2015-06-24  3:37 UTC (permalink / raw)
  To: alexey.kodanev; +Cc: ltp-list

On Tue, 2015-06-23 at 13:06 +0300, Alexey Kodanev wrote:
> Hi!
> On 06/23/2015 04:02 AM, Wei,Jiangang wrote:
> > * 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(-)
> 
> Please look at "[LTP] [PATCH]: Fix memory leak by freeing buf" thread.

Thanks for your reminder.
I will update my patch.

Regard,
wei
> 
> Thanks,
> Alexey
> 

------------------------------------------------------------------------------
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	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2] sem_conpro: cleanup code
  2015-06-23 10:06 ` Alexey Kodanev
  2015-06-24  3:37   ` Wei, Jiangang
@ 2015-06-24  3:41   ` Wei,Jiangang
  2015-06-25 13:46     ` Alexey Kodanev
  1 sibling, 1 reply; 5+ messages in thread
From: Wei,Jiangang @ 2015-06-24  3:41 UTC (permalink / raw)
  To: ltp-list

* It's reasonable to allocate memory after checking
  _POSIX_SEMAPHORES.
  Allocate 'buf' on the stack to avoid the problem.

* remove meaningless printf()

Signed-off-by: Wei,Jiangang <weijg.fnst@cn.fujitsu.com>
---
 .../functional/semaphores/sem_conpro.c                 | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c b/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
index f5f1abf..2fb9890 100644
--- a/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
+++ b/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
@@ -100,34 +100,32 @@ int main(int argc, char *argv[])
 	int occupied_value = BUF_SIZE;
 	int empty_value = 0;
 	int lock_value = 1;
-	buf_t *buf;
+	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
-	if (-1 == sem_init(&(buf->occupied), shared, occupied_value)) {
+	if (-1 == sem_init(&buf.occupied, shared, occupied_value)) {
 		perror("sem_init didn't return success \n");
-		printf("hello \n");
 		return PTS_UNRESOLVED;
 	}
-	if (-1 == sem_init(&buf->empty, shared, empty_value)) {
+	if (-1 == sem_init(&buf.empty, shared, empty_value)) {
 		perror("sem_init didn't return success \n");
 		return PTS_UNRESOLVED;
 	}
-	if (-1 == sem_init(&buf->lock, shared, lock_value)) {
+	if (-1 == sem_init(&buf.lock, shared, lock_value)) {
 		perror("sem_init didn't return success \n");
 		return PTS_UNRESOLVED;
 	}
 	in = out = 0;
 
-	pthread_create(&con, NULL, (void *)consumer, (void *)buf);
-	pthread_create(&pro, NULL, (void *)producer, (void *)buf);
+	pthread_create(&con, NULL, (void *)consumer, (void *)&buf);
+	pthread_create(&pro, NULL, (void *)producer, (void *)&buf);
 	pthread_join(con, NULL);
 	pthread_join(pro, NULL);
-	sem_destroy(&buf->occupied);
-	sem_destroy(&buf->empty);
+	sem_destroy(&buf.occupied);
+	sem_destroy(&buf.empty);
 	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

* Re: [LTP] [PATCH v2] sem_conpro: cleanup code
  2015-06-24  3:41   ` [LTP] [PATCH v2] sem_conpro: cleanup code Wei,Jiangang
@ 2015-06-25 13:46     ` Alexey Kodanev
  0 siblings, 0 replies; 5+ messages in thread
From: Alexey Kodanev @ 2015-06-25 13:46 UTC (permalink / raw)
  To: Wei, Jiangang, ltp-list

Hi!
On 06/24/2015 06:41 AM, Wei,Jiangang wrote:
> * It's reasonable to allocate memory after checking
>    _POSIX_SEMAPHORES.
>    Allocate 'buf' on the stack to avoid the problem.
>
> * remove meaningless printf()
>

Patch applied. Also removed not needed void cast and fix commit message.

Thanks,
Alexey


------------------------------------------------------------------------------
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	[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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.