Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'sctp_do_bind-leak'

Mao Wenan says:

====================
fix memory leak for sctp_do_bind

First two patches are to do cleanup, remove redundant assignment,
and change return type of sctp_get_port_local.
Third patch is to fix memory leak for sctp_do_bind if failed
to bind address.

v2: add one patch to change return type of sctp_get_port_local.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+11 -10
+11 -10
net/sctp/socket.c
··· 309 309 return retval; 310 310 } 311 311 312 - static long sctp_get_port_local(struct sock *, union sctp_addr *); 312 + static int sctp_get_port_local(struct sock *, union sctp_addr *); 313 313 314 314 /* Verify this is a valid sockaddr. */ 315 315 static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt, ··· 399 399 * detection. 400 400 */ 401 401 addr->v4.sin_port = htons(snum); 402 - if ((ret = sctp_get_port_local(sk, addr))) { 402 + if (sctp_get_port_local(sk, addr)) 403 403 return -EADDRINUSE; 404 - } 405 404 406 405 /* Refresh ephemeral port. */ 407 406 if (!bp->port) ··· 412 413 ret = sctp_add_bind_addr(bp, addr, af->sockaddr_len, 413 414 SCTP_ADDR_SRC, GFP_ATOMIC); 414 415 415 - /* Copy back into socket for getsockname() use. */ 416 - if (!ret) { 417 - inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num); 418 - sp->pf->to_sk_saddr(addr, sk); 416 + if (ret) { 417 + sctp_put_port(sk); 418 + return ret; 419 419 } 420 + /* Copy back into socket for getsockname() use. */ 421 + inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num); 422 + sp->pf->to_sk_saddr(addr, sk); 420 423 421 424 return ret; 422 425 } ··· 8000 7999 static struct sctp_bind_bucket *sctp_bucket_create( 8001 8000 struct sctp_bind_hashbucket *head, struct net *, unsigned short snum); 8002 8001 8003 - static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) 8002 + static int sctp_get_port_local(struct sock *sk, union sctp_addr *addr) 8004 8003 { 8005 8004 struct sctp_sock *sp = sctp_sk(sk); 8006 8005 bool reuse = (sk->sk_reuse || sp->reuse); ··· 8110 8109 8111 8110 if (sctp_bind_addr_conflict(&ep2->base.bind_addr, 8112 8111 addr, sp2, sp)) { 8113 - ret = (long)sk2; 8112 + ret = 1; 8114 8113 goto fail_unlock; 8115 8114 } 8116 8115 } ··· 8182 8181 addr.v4.sin_port = htons(snum); 8183 8182 8184 8183 /* Note: sk->sk_num gets filled in if ephemeral port request. */ 8185 - return !!sctp_get_port_local(sk, &addr); 8184 + return sctp_get_port_local(sk, &addr); 8186 8185 } 8187 8186 8188 8187 /*