diff options
Diffstat (limited to 'src/request.c')
| -rw-r--r-- | src/request.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/request.c b/src/request.c index 56bf47b..fd868f8 100644 --- a/src/request.c +++ b/src/request.c @@ -1,5 +1,6 @@ #include "libhttpc.h" +#include <errno.h> #include <stddef.h> #include <string.h> @@ -14,6 +15,8 @@ struct LibHTTPC_Request *LibHTTPC_loadRequest(struct LibHTTPC_Request *request_b if (!request_buf) { + if (!LibHTTPC_malloc || !LibHTTPC_realloc) + return NULL; request_buf = LibHTTPC_malloc(sizeof(struct LibHTTPC_Request)); memset(request_buf, '\0', sizeof(struct LibHTTPC_Request)); request_buf->selfalloc = 1; @@ -52,6 +55,8 @@ struct LibHTTPC_Request *LibHTTPC_loadRequest(struct LibHTTPC_Request *request_b if (selfmalloc) { + if (!LibHTTPC_malloc || !LibHTTPC_realloc) + return NULL; ++request_buf->header_count; if (!request_buf->headers) request_buf->headers = LibHTTPC_malloc(sizeof(struct LibHTTPC_Header)); @@ -71,10 +76,14 @@ struct LibHTTPC_Request *LibHTTPC_loadRequest(struct LibHTTPC_Request *request_b return request_buf; } -void LibHTTPC_Request_(struct LibHTTPC_Request *request) +int LibHTTPC_Request_(struct LibHTTPC_Request *request) { + if (!LibHTTPC_free) + return -1; + if (request->header_selfalloc) LibHTTPC_free(request->headers); if (request->selfalloc) LibHTTPC_free(request); + return errno; } |