--- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -1796,7 +1796,7 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc, bool wait_connect = false; struct sctp_chunk *chunk; long timeo; - int err; + int err, mem = 0; if (sinfo->sinfo_stream >= asoc->stream.outcnt) { err = -EINVAL; @@ -1807,11 +1807,12 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc, err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream); if (err) goto err; + mem = 1; } if (sp->disable_fragments && msg_len > asoc->frag_point) { err = -EMSGSIZE; - goto err; + goto free_mem; } if (asoc->pmtu_pending) { @@ -1883,6 +1884,10 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc, err = msg_len; +free_mem: + if (mem) + sctp_stream_free(&asoc->stream); + err: return err; }