usock doesn't handle memory allocation anymore

pollfd
Karchnu 2020-07-08 13:38:48 +02:00
parent 8ccefcc40f
commit 0a8680a7e8
2 changed files with 8 additions and 17 deletions

View File

@ -32,3 +32,11 @@ To remove logs: `make LDFLAGS=-DIPC_WITHOUT_ERRORS`
# Planning for 1.0
- `libipc` should have usable bindings in several languages
# Implementation design
## Memory management
1. Prefer stack over mallocs.
2. Basic functions (such as *usock_*) should not handle memory allocation.

View File

@ -40,15 +40,6 @@ struct ipc_error usock_recv (const int32_t fd, char **buf, size_t * len)
if (*len == 0)
*len = IPC_MAX_MESSAGE_SIZE;
if (*buf == NULL) {
// do not allocate too much memory
if (*len > IPC_MAX_MESSAGE_SIZE) {
*len = IPC_MAX_MESSAGE_SIZE;
}
SECURE_BUFFER_HEAP_ALLOCATION (*buf, *len + IPC_HEADER_SIZE,,
IPC_RETURN_ERROR (IPC_ERROR_USOCK_RECV__HEAP_ALLOCATION));
}
uint32_t msize = 0;
uint32_t msize_read = 0;
@ -76,10 +67,6 @@ struct ipc_error usock_recv (const int32_t fd, char **buf, size_t * len)
T_R ((msize > IPC_MAX_MESSAGE_SIZE), IPC_ERROR_USOCK_RECV__MESSAGE_SIZE);
msize_read += ret_recv - IPC_HEADER_SIZE;
} else if (ret_recv < 0) {
if (*buf != NULL) {
free (*buf);
*buf = NULL;
}
*len = 0;
switch (errno) {
@ -130,10 +117,6 @@ struct ipc_error usock_recv (const int32_t fd, char **buf, size_t * len)
// 1 on none byte received, indicates a closed recipient
if (ret_recv == 0) {
if (*buf != NULL) {
free (*buf);
*buf = NULL;
}
*len = 0;
IPC_RETURN_ERROR (IPC_ERROR_CLOSED_RECIPIENT);
}