Hi, Yes , we can make 'found' a static array.It will do the same purpose ,also we dont need to add further error checking code for malloc and then free(). Here is the patch:
From: Manjeet Pawar <manjee...@samsung.com> Date: Tue, 9 Jun 2015 17:28:06 +0530 Subject: [PATCH] utils/sctp/testlib/sctputil.c: make 'found' a static array instead of dynamic memory to avoid memory leak This patch make 'found' a static array to avoid memory leaks. Signed-off-by: Cyril Hrubis <chru...@suse.cz> Signed-off-by: Manjeet Pawar <manjee...@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) { -- 1.7.1 ------- Original Message ------- Sender : Cyril Hrubis<chru...@suse.cz> Date : Jun 09, 2015 01:48 (GMT+09:00) Title : Re: [LTP] [PATCH]: Fix memory leak 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 chru...@suse.cz ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list