diff options
| author | Nakidai <nakidai@disroot.org> | 2024-11-29 10:00:42 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-11-29 10:00:42 +0300 |
| commit | 2502543936a8523a24b630ca49b3185ebfd724d5 (patch) | |
| tree | 4427cc71b2f9b7e988a1427f40b0db583812d993 /src/request.c | |
| parent | 88809188ecb22f6221f79d2dbe8c6544c63b885f (diff) | |
| download | libhttpc-2502543936a8523a24b630ca49b3185ebfd724d5.tar.gz libhttpc-2502543936a8523a24b630ca49b3185ebfd724d5.zip | |
Add some checks
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; } |