diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-02-25 21:04:19 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-02-25 21:04:19 -0800 |
| commit | 6a59b15fba1085432c4c18952680e14d80dd134a (patch) | |
| tree | ccdfae8ef436fa47cdf79544b54ed73d4b668597 /src | |
| parent | 57e315d7b3a2baf38ec3085faf59c4aef4a0ab9e (diff) | |
| download | nng-6a59b15fba1085432c4c18952680e14d80dd134a.tar.gz nng-6a59b15fba1085432c4c18952680e14d80dd134a.tar.bz2 nng-6a59b15fba1085432c4c18952680e14d80dd134a.zip | |
fixes #1201 Unexpected error return code: NNG_ENOMEM
Diffstat (limited to 'src')
| -rw-r--r-- | src/nng.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -105,14 +105,19 @@ nng_recv(nng_socket s, void *buf, size_t *szp, int flags) // better use nng_recvmsg() instead. void *nbuf; - if ((nbuf = nni_alloc(nng_msg_len(msg))) == NULL) { - nng_msg_free(msg); - return (NNG_ENOMEM); + if (nng_msg_len(msg) != 0) { + if ((nbuf = nni_alloc(nng_msg_len(msg))) == NULL) { + nng_msg_free(msg); + return (NNG_ENOMEM); + } + + *(void **) buf = nbuf; + memcpy(nbuf, nni_msg_body(msg), nni_msg_len(msg)); + *szp = nng_msg_len(msg); + } else { + *(void **)buf = NULL; + *szp = 0; } - - *(void **) buf = nbuf; - memcpy(nbuf, nni_msg_body(msg), nni_msg_len(msg)); - *szp = nng_msg_len(msg); } nni_msg_free(msg); return (0); |
