You've already forked hexagonrpc
mirror of
https://github.com/linux-msm/hexagonrpc.git
synced 2026-02-25 13:13:52 -08:00
fastrpc: hexagonrpcd: listener: do not attempt to allocate zero outbufs
The malloc(3p) manual page states that an implementation may choose to return a non-NULL pointer when the size is zero. This function assumes that there is an element in the array if the pointer is not NULL. When the size is zero, skip the allocation and return NULL.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user