about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2024-11-29 10:00:42 +0300
committerNakidai <nakidai@disroot.org>2024-11-29 10:00:42 +0300
commit2502543936a8523a24b630ca49b3185ebfd724d5 (patch)
tree4427cc71b2f9b7e988a1427f40b0db583812d993 /src
parent88809188ecb22f6221f79d2dbe8c6544c63b885f (diff)
downloadlibhttpc-2502543936a8523a24b630ca49b3185ebfd724d5.tar.gz
libhttpc-2502543936a8523a24b630ca49b3185ebfd724d5.zip
Add some checks
Diffstat (limited to 'src')
-rw-r--r--src/request.c11
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;
 }