public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP]  [PATCH]: Fix memory leak
@ 2015-06-08  4:00 Manjeet Pawar
  2015-06-08 16:48 ` Cyril Hrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Manjeet Pawar @ 2015-06-08  4:00 UTC (permalink / raw)
  To: ltp-list@lists.sourceforge.net; +Cc: ajeet.y@samsung.com, akhilesh.k

From: Manjeet Pawar <manjeet.p@samsung.com>
Subject: [PATCH] utils/sctp/testlib/sctputil.c: Fix memory leak

This patch frees the allocated memory (used for checking peer addresses) before returning from function.

Signed-off-by: Akhilesh Kumar <akhilesh.k@samsung.com>
Signed-off-by: Manjeet Pawar <manjeet.p@samsung.com>
---
 utils/sctp/testlib/sctputil.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/utils/sctp/testlib/sctputil.c b/utils/sctp/testlib/sctputil.c
index c670af6..283b5a7 100644
--- a/utils/sctp/testlib/sctputil.c
+++ b/utils/sctp/testlib/sctputil.c
@@ -376,6 +376,7 @@ int test_peer_addr(int sk, sctp_assoc_t asoc, sockaddr_storage_t *peers, int cou
 	error = sctp_getpaddrs(sk, asoc, &addrs);
 	if (-1 == error) {
 		tst_brkm(TBROK, tst_exit, "sctp_getpaddrs: %s", strerror(errno));
+		free(found);
 		return error;
 	}
 	if (error != count) {
@@ -399,6 +400,7 @@ int test_peer_addr(int sk, sctp_assoc_t asoc, sockaddr_storage_t *peers, int cou
 			errno = EINVAL;
 			sctp_freepaddrs(addrs);
 			tst_brkm(TBROK, tst_exit, "sctp_getpaddrs: %s", strerror(errno));
+			free(found);
 			return -1;
 		}
 		for (j = 0; j < count; j++) {
@@ -414,5 +416,6 @@ int test_peer_addr(int sk, sctp_assoc_t asoc, sockaddr_storage_t *peers, int cou
 		}
 	}
 	sctp_freepaddrs(addrs);
+	free(found);
 	return 0;
 }
-- 
1.7.1

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH]: Fix memory leak
  2015-06-08  4:00 Manjeet Pawar
@ 2015-06-08 16:48 ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2015-06-08 16:48 UTC (permalink / raw)
  To: Manjeet Pawar
  Cc: ajeet.y@samsung.com, ltp-list@lists.sourceforge.net, akhilesh.k

Hi!
There is also missing check for the return from malloc().

And given that we do not return the pointer to the array and that the
cound is at most 6, what about changing the malloc() to array on stack?

I.e.

- char *found = (char *) malloc(count);
- memset(found, 0, count);
+ char found[count];

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH]: Fix memory leak
       [not found] <481574461.737361433821252744.JavaMail.weblogic@epmlwas02a>
@ 2015-06-09  9:00 ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2015-06-09  9:00 UTC (permalink / raw)
  To: Manjeet Pawar; +Cc: AJEET YADAV, ltp-list@lists.sourceforge.net, AKHILESH KUMAR

Hi!
> This patch make 'found' a static array to avoid memory leaks.
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Manjeet Pawar <manjeet.p@samsung.com>
> ---
>  utils/sctp/testlib/sctputil.c |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
> 
> diff --git a/utils/sctp/testlib/sctputil.c b/utils/sctp/testlib/sctputil.c
> index c670af6..e7333e5 100644
> --- a/utils/sctp/testlib/sctputil.c
> +++ b/utils/sctp/testlib/sctputil.c
> @@ -370,8 +370,7 @@ int test_peer_addr(int sk, sctp_assoc_t asoc, sockaddr_storage_t *peers, int cou
>  	struct sockaddr *sa_addr;
>  	socklen_t addrs_size = 0;
>  	void *addrbuf;
> -	char *found = (char *) malloc(count);
> -	memset(found, 0, count);
> +	char found[count];
>  
>  	error = sctp_getpaddrs(sk, asoc, &addrs);
>  	if (-1 == error) {

I've added initialization to 0 to the else branch down below, since we
removed the memset and pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH]: Fix memory leak
       [not found] <BA.2A.27612.361B6755@epcpsbgx1.samsung.com>
@ 2015-06-09 10:35 ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2015-06-09 10:35 UTC (permalink / raw)
  To: Manjeet Pawar; +Cc: AJEET YADAV, ltp-list@lists.sourceforge.net, AKHILESH KUMAR

Hi!
No HTML emails please.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2015-06-09 10:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <481574461.737361433821252744.JavaMail.weblogic@epmlwas02a>
2015-06-09  9:00 ` [LTP] [PATCH]: Fix memory leak Cyril Hrubis
     [not found] <BA.2A.27612.361B6755@epcpsbgx1.samsung.com>
2015-06-09 10:35 ` Cyril Hrubis
2015-06-08  4:00 Manjeet Pawar
2015-06-08 16:48 ` Cyril Hrubis

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