diff options
| -rw-r--r-- | include/libhttpc.h | 3 | ||||
| -rw-r--r-- | src/request.c | 11 |
2 files changed, 12 insertions, 2 deletions
diff --git a/include/libhttpc.h b/include/libhttpc.h index e64361c..702a662 100644 --- a/include/libhttpc.h +++ b/include/libhttpc.h @@ -269,8 +269,9 @@ char *LibHTTPC_dumpResponse(struct LibHTTPC_Response *response, char *buf, size_ /** * Destructor for LibHTTPC_Request * @param request Request to free + * @return -1 if LibHTTPC_free is not set, errno otherwise */ -void LibHTTPC_Request_(struct LibHTTPC_Request *request); +int LibHTTPC_Request_(struct LibHTTPC_Request *request); /** * Not implemented yet 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; } |