: Fix memory leak
PATCH 1/1 : Fix memory leak
From: Manjeet Pawar <[email protected]>
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 <[email protected]>
Signed-off-by Manjeet Pawar <[email protected]>
--- utils/sctp/testlib/sctputil.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
utils/sctp/testlib/sctputil.c +3 -0
@@ -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 ; }
Signature · 7 lines
1.7.1 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
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];
Signature · 8 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list