From 7afc254cd4dd72f125968f1331a48031f65b02fa Mon Sep 17 00:00:00 2001 From: Lawrence Kesteloot Date: Fri, 14 Sep 2018 21:51:54 -0700 Subject: Only free in nng_send() if we succeed. Both the man page and the comment (in nng.h) of nng_send() say that the buffer is freed only if the function succeeds. The previous code always freed (if the flag was set). This change only frees if we succeed. --- src/nng.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nng.c b/src/nng.c index f98727ce..a8d4bd24 100644 --- a/src/nng.c +++ b/src/nng.c @@ -158,10 +158,12 @@ nng_send(nng_socket s, void *buf, size_t len, int flags) } memcpy(nng_msg_body(msg), buf, len); if ((rv = nng_sendmsg(s, msg, flags)) != 0) { + // If nng_sendmsg() succeeded, then it took ownership. nng_msg_free(msg); - } - if (flags & NNG_FLAG_ALLOC) { - nni_free(buf, len); + } else { + if (flags & NNG_FLAG_ALLOC) { + nni_free(buf, len); + } } return (rv); } -- cgit v1.2.3-70-g09d2