7ecba4e0d5
CI / lint (pull_request) Failing after 3s
CI / build-and-test (pull_request) Has been skipped
CI / sanitizers (address) (pull_request) Has been skipped
CI / sanitizers (undefined) (pull_request) Has been skipped
CI / fuzz-build (pull_request) Has been skipped
CI / coverage (pull_request) Has been skipped
CI / valgrind (pull_request) Has been skipped
- Fix transport_tcp.c: initialize server->ssl_ctx to NULL (prevents SSL_CTX_free on garbage when server_create_tls fails) - Fix test_transport_tcp.c: client_create now sets fd=-1, family=AF_UNSPEC - Fix test_transport_tcp.c: server address family may be AF_INET or AF_INET6 - Fix test_file_sendfile.c: send_path=false protocol includes file_type prefix
45 lines
1.0 KiB
C
45 lines
1.0 KiB
C
#include "data.h"
|
|
#include "log.h"
|
|
#include "stdlib.h"
|
|
|
|
Data* data_create_empty(size_t data_size) {
|
|
/* malloc(0) is UB; allocate at least 1 byte but preserve requested size */
|
|
size_t alloc_size = data_size > 0 ? data_size : 1;
|
|
void* data = malloc(alloc_size);
|
|
if (data == NULL) {
|
|
log_message(LOG_LEVEL_ERROR, "Could not allocate memory for empty data");
|
|
return NULL;
|
|
}
|
|
return data_create(data, data_size);
|
|
}
|
|
|
|
Data* data_create_reserve(size_t size) {
|
|
Data* d = malloc(sizeof(Data));
|
|
if (d == NULL) {
|
|
log_message(LOG_LEVEL_ERROR, "Could not allocate memory for data");
|
|
return NULL;
|
|
}
|
|
d->data = NULL;
|
|
d->size = size;
|
|
return d;
|
|
}
|
|
|
|
Data* data_create(void* data, size_t data_size) {
|
|
Data* new_data = malloc(sizeof(Data));
|
|
if (new_data == NULL) {
|
|
log_message(LOG_LEVEL_ERROR, "Could not allocate memory for data");
|
|
free(data);
|
|
return NULL;
|
|
}
|
|
new_data->data = data;
|
|
new_data->size = data_size;
|
|
return new_data;
|
|
}
|
|
|
|
void data_destroy(Data* data) {
|
|
if (data == NULL)
|
|
return;
|
|
free(data->data);
|
|
free(data);
|
|
}
|