From 8bea70c68e3f7ac23d4ff10b758af718ffb94263 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 6 Aug 2018 21:26:31 +0300 Subject: fixes #611 Memory Leaks under Windows fixes #622 incorrect assumptions about malloc(0) Windows actually allocates an object of size zero when calling malloc on size zero. This is unusual behavior, and we just add logic to work more like malloc on POSIX systems. Other systems can return non-NULL objects to fixed pages here. We think the best option here is to uniformly return NULL from our APIs in these circumstances, and to include testing to validate that. --- src/protocol/pubsub0/sub.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/protocol/pubsub0/sub.c') diff --git a/src/protocol/pubsub0/sub.c b/src/protocol/pubsub0/sub.c index cb6d781f..aeccfd25 100644 --- a/src/protocol/pubsub0/sub.c +++ b/src/protocol/pubsub0/sub.c @@ -228,9 +228,13 @@ sub0_subscribe(void *arg, const void *buf, size_t sz, nni_opt_type t) nni_mtx_unlock(&s->lk); return (NNG_ENOMEM); } - if ((newtopic->buf = nni_alloc(sz)) == NULL) { - nni_mtx_unlock(&s->lk); - return (NNG_ENOMEM); + if (sz > 0) { + if ((newtopic->buf = nni_alloc(sz)) == NULL) { + nni_mtx_unlock(&s->lk); + return (NNG_ENOMEM); + } + } else { + newtopic->buf = NULL; } NNI_LIST_NODE_INIT(&newtopic->node); newtopic->len = sz; -- cgit v1.2.3-70-g09d2