diff --git a/fastrpc/hexagonrpcd/listener.c b/fastrpc/hexagonrpcd/listener.c index d746146..bcdc857 100644 --- a/fastrpc/hexagonrpcd/listener.c +++ b/fastrpc/hexagonrpcd/listener.c @@ -73,6 +73,14 @@ static struct fastrpc_io_buffer *allocate_outbufs(const struct fastrpc_function_ off_t off; uint32_t *sizes; + /* + * POSIX allows malloc to return a non-NULL pointer to a zero-size area + * in memory. Since the code below assumes non-zero size if the pointer + * is non-NULL, exit early if we do not need to allocate anything. + */ + if (out_count == 0) + return NULL; + out_count = def->out_bufs + (def->out_nums && 1); out = malloc(sizeof(struct fastrpc_io_buffer) * out_count); if (out == NULL)