All of lore.kernel.org
 help / color / mirror / Atom feed
* v2 [PATCH] sctp_xconnect: memory leak when malloc big buffer
@ 2013-01-15  1:52 Fan Du
  2013-01-15 12:43 ` Neil Horman
  2013-01-15 13:14 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Fan Du @ 2013-01-15  1:52 UTC (permalink / raw)
  To: linux-sctp

sctp_xconnect: memory leak when malloc big buffer

CLIENT repeatly call process_ready_sockets, which malloc without free,
so sctp_xconnect exit unexpectly.

Signed-off-by: Fan Du <fan.du@windriver.com>
v1->v2:
Declare this buffer statically suggested by Neil Horman.

---
 apps/sctp_xconnect.c |   12 +-----------
 1 files changed, 1 insertions(+), 11 deletions(-)

diff --git a/apps/sctp_xconnect.c b/apps/sctp_xconnect.c
index 5874c33..06ab29c 100644
--- a/apps/sctp_xconnect.c
+++ b/apps/sctp_xconnect.c
@@ -73,6 +73,7 @@ char *remote_host = NULL;
 sockaddr_storage_t client_loop,
 		server_loop;
 struct hostent *hst;
+char big_buffer[REALLY_BIG];
 
 void usage(char *argv0);
 void parse_arguments(int argc, char*argv[]);
@@ -380,13 +381,8 @@ void server_mode() {
 	int assoc_num =0;
 	struct msghdr inmessage;
 	struct iovec iov;
-	char *big_buffer;
 	char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))];
 
-	if ((big_buffer = malloc(REALLY_BIG)) = NULL) {
-		printf("malloc failure: %s\n", strerror(errno));
-		DUMP_CORE;
-	}
 
 	printf("Running in Server Mode...\n");
 
@@ -530,15 +526,9 @@ void process_ready_sockets(int client_socket[], int assoc_num, fd_set *rfds) {
         int i, stream, error;
 	struct msghdr inmessage;
 	struct iovec iov;
-	char *big_buffer;
 	char incmsg[CMSG_SPACE(sizeof (sctp_cmsg_data_t))];
 	sockaddr_storage_t msgname;
 
-	if ((big_buffer = malloc(REALLY_BIG)) = NULL) {
-		printf("malloc failure: %s\n", strerror(errno));
-		DUMP_CORE;
-	}
-
         /* Setup inmessage to be able to receive in incomming message */
 	memset(&inmessage, 0, sizeof (inmessage));
 	iov.iov_base = big_buffer;
-- 
1.7.1


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

* Re: v2 [PATCH] sctp_xconnect: memory leak when malloc big buffer
  2013-01-15  1:52 v2 [PATCH] sctp_xconnect: memory leak when malloc big buffer Fan Du
@ 2013-01-15 12:43 ` Neil Horman
  2013-01-15 13:14 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Neil Horman @ 2013-01-15 12:43 UTC (permalink / raw)
  To: linux-sctp

On Tue, Jan 15, 2013 at 09:52:03AM +0800, Fan Du wrote:
> sctp_xconnect: memory leak when malloc big buffer
> 
> CLIENT repeatly call process_ready_sockets, which malloc without free,
> so sctp_xconnect exit unexpectly.
> 
> Signed-off-by: Fan Du <fan.du@windriver.com>
> v1->v2:
> Declare this buffer statically suggested by Neil Horman.
> 
> ---
>  apps/sctp_xconnect.c |   12 +-----------
>  1 files changed, 1 insertions(+), 11 deletions(-)
> 
> diff --git a/apps/sctp_xconnect.c b/apps/sctp_xconnect.c
> index 5874c33..06ab29c 100644
> --- a/apps/sctp_xconnect.c
> +++ b/apps/sctp_xconnect.c
> @@ -73,6 +73,7 @@ char *remote_host = NULL;
>  sockaddr_storage_t client_loop,
>  		server_loop;
>  struct hostent *hst;
> +char big_buffer[REALLY_BIG];
>  
>  void usage(char *argv0);
>  void parse_arguments(int argc, char*argv[]);
> @@ -380,13 +381,8 @@ void server_mode() {
>  	int assoc_num =0;
>  	struct msghdr inmessage;
>  	struct iovec iov;
> -	char *big_buffer;
>  	char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))];
>  
> -	if ((big_buffer = malloc(REALLY_BIG)) = NULL) {
> -		printf("malloc failure: %s\n", strerror(errno));
> -		DUMP_CORE;
> -	}
>  
>  	printf("Running in Server Mode...\n");
>  
> @@ -530,15 +526,9 @@ void process_ready_sockets(int client_socket[], int assoc_num, fd_set *rfds) {
>          int i, stream, error;
>  	struct msghdr inmessage;
>  	struct iovec iov;
> -	char *big_buffer;
>  	char incmsg[CMSG_SPACE(sizeof (sctp_cmsg_data_t))];
>  	sockaddr_storage_t msgname;
>  
> -	if ((big_buffer = malloc(REALLY_BIG)) = NULL) {
> -		printf("malloc failure: %s\n", strerror(errno));
> -		DUMP_CORE;
> -	}
> -
>          /* Setup inmessage to be able to receive in incomming message */
>  	memset(&inmessage, 0, sizeof (inmessage));
>  	iov.iov_base = big_buffer;
> -- 
> 1.7.1
> 
> 

Looks good, thank you!
Acked-by: Neil Horman <nhorman@tuxdriver.com>


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

* Re: v2 [PATCH] sctp_xconnect: memory leak when malloc big buffer
  2013-01-15  1:52 v2 [PATCH] sctp_xconnect: memory leak when malloc big buffer Fan Du
  2013-01-15 12:43 ` Neil Horman
@ 2013-01-15 13:14 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2013-01-15 13:14 UTC (permalink / raw)
  To: linux-sctp

On 01/15/2013 01:43 PM, Neil Horman wrote:
> On Tue, Jan 15, 2013 at 09:52:03AM +0800, Fan Du wrote:
>> sctp_xconnect: memory leak when malloc big buffer
>>
>> CLIENT repeatly call process_ready_sockets, which malloc without free,
>> so sctp_xconnect exit unexpectly.
>>
>> Signed-off-by: Fan Du <fan.du@windriver.com>
>> v1->v2:
>> Declare this buffer statically suggested by Neil Horman.

[...]

> Looks good, thank you!
> Acked-by: Neil Horman <nhorman@tuxdriver.com>

Applied, thanks Fan.

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

end of thread, other threads:[~2013-01-15 13:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-15  1:52 v2 [PATCH] sctp_xconnect: memory leak when malloc big buffer Fan Du
2013-01-15 12:43 ` Neil Horman
2013-01-15 13:14 ` Daniel Borkmann

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.