aboutsummaryrefslogtreecommitdiff
path: root/src/nng.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nng.c')
-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);
}