[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-sctp
Subject: RE: [PATCH lksctp-tools 1/5] fix memory leak in sctp_status
From: David Laight <David.Laight () ACULAB ! COM>
Date: 2023-02-16 12:43:00
Message-ID: e34861ea17504d11aab77ca18da20d96 () AcuMS ! aculab ! com
[Download RAW message or body]
Freeing memory before exit() is a waste of time.
(and don't talk to me about calling C++ destructors)
David
> -----Original Message-----
> From: Qiumiao Zhang <zhangqiumiao1@huawei.com>
> Sent: 16 February 2023 11:48
> To: linux-sctp@vger.kernel.org; marcelo.leitner@gmail.com
> Cc: zhaowei23@huawei.com; caowangbao@huawei.com; yanan@huawei.com; zhangqiumiao1@huawei.com
> Subject: [PATCH lksctp-tools 1/5] fix memory leak in sctp_status
>
> Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
> ---
> src/apps/sctp_status.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/src/apps/sctp_status.c b/src/apps/sctp_status.c
> index 7c18ab1..5a52165 100644
> --- a/src/apps/sctp_status.c
> +++ b/src/apps/sctp_status.c
> @@ -266,6 +266,7 @@ int main(int argc, char *argv[]) {
> }
> if ((serv_s = malloc(NI_MAXSERV)) == NULL) {
> fprintf(stderr, "\n*** serv_s malloc failed!!! ***\n");
> + free(host_s);
> exit(1);
> }
>
> @@ -273,6 +274,8 @@ int main(int argc, char *argv[]) {
> if (error) {
> printf("%s.\n", gai_strerror(error));
> usage(argv[0]);
> + free(host_s);
> + free(serv_s);
> exit(1);
> }
>
> @@ -315,6 +318,8 @@ int main(int argc, char *argv[]) {
> host_s, serv_s, res->ai_family);
>
> freeaddrinfo(res);
> + free(host_s);
> + free(serv_s);
> }
>
> if (local_host != NULL) {
> @@ -330,6 +335,7 @@ int main(int argc, char *argv[]) {
> }
> if ((serv_s = malloc(NI_MAXSERV)) == NULL) {
> fprintf(stderr, "\n*** serv_s malloc failed!!! ***\n");
> + free(host_s);
> exit(1);
> }
>
> @@ -340,6 +346,8 @@ int main(int argc, char *argv[]) {
> if (error) {
> printf("%s.\n", gai_strerror(error));
> usage(argv[0]);
> + free(host_s);
> + free(serv_s);
> exit(1);
> }
>
> @@ -385,6 +393,8 @@ int main(int argc, char *argv[]) {
> host_s, serv_s, res->ai_family);
>
> freeaddrinfo(res);
> + free(host_s);
> + free(serv_s);
> }
>
> /* Let the testing begin. */
> @@ -403,6 +413,7 @@ int bind_r(int sk, struct sockaddr_storage *saddr) {
> }
> if ((serv_s = malloc(NI_MAXSERV)) == NULL) {
> fprintf(stderr, "\n\t\t*** serv_s malloc failed!!! ***\n");
> + free(host_s);
> exit(1);
> }
>
> @@ -427,6 +438,8 @@ int bind_r(int sk, struct sockaddr_storage *saddr) {
> fprintf(stderr, "\n\n\t\t***bind: can "
> "not bind to %s:%s: %s ****\n",
> host_s, serv_s, strerror(errno));
> + free(host_s);
> + free(serv_s);
> exit(1);
> }
> }
> @@ -434,6 +447,8 @@ int bind_r(int sk, struct sockaddr_storage *saddr) {
> if (i >= MAX_BIND_RETRYS) {
> fprintf(stderr, "Maximum bind() attempts. "
> "Die now...\n\n");
> + free(host_s);
> + free(serv_s);
> exit(1);
> }
> } while (error < 0 && i < MAX_BIND_RETRYS);
> --
> 2.27.0
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic