summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawrence Kesteloot <lk@teamten.com>2018-09-14 21:51:54 -0700
committerGarrett D'Amore <garrett@damore.org>2018-09-15 13:30:05 -0700
commit7afc254cd4dd72f125968f1331a48031f65b02fa (patch)
treeb83f7ef5d65b5f6f15c02de0f8f8b12b6fb1123d
parent0863d12e2b5173efeb074cbc9fa05f26274f126b (diff)
downloadnng-7afc254cd4dd72f125968f1331a48031f65b02fa.tar.gz
nng-7afc254cd4dd72f125968f1331a48031f65b02fa.tar.bz2
nng-7afc254cd4dd72f125968f1331a48031f65b02fa.zip
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.
-rw-r--r--src/nng.c8
1 files 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);
}