From 2502543936a8523a24b630ca49b3185ebfd724d5 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Fri, 29 Nov 2024 10:00:42 +0300 Subject: Add some checks --- src/request.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/request.c') 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 #include #include @@ -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; } -- cgit 1.4.1