summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/download.c7
-rw-r--r--src/restore.c7
2 files changed, 12 insertions, 2 deletions
diff --git a/src/download.c b/src/download.c
index 0b6b076..5910667 100644
--- a/src/download.c
+++ b/src/download.c
@@ -35,7 +35,12 @@ typedef struct {
static size_t download_write_buffer_callback(char* data, size_t size, size_t nmemb, curl_response* response) {
size_t total = size * nmemb;
if (total != 0) {
- response->content = realloc(response->content, response->length + total + 1);
+ char* new_content = realloc(response->content, response->length + total + 1);
+ if (!new_content) {
+ /* keep the data received so far; returning a short count makes curl abort the transfer */
+ return 0;
+ }
+ response->content = new_content;
memcpy(response->content + response->length, data, total);
response->content[response->length + total] = '\0';
response->length += total;
diff --git a/src/restore.c b/src/restore.c
index a69c581..e220598 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -1333,7 +1333,12 @@ static size_t _curl_write_callback(char* data, size_t size, size_t nmemb, query_
{
size_t total = size * nmemb;
if (total != 0) {
- response->content = realloc(response->content, response->length + total + 1);
+ char* new_content = realloc(response->content, response->length + total + 1);
+ if (!new_content) {
+ /* keep the data received so far; returning a short count makes curl abort the transfer */
+ return 0;
+ }
+ response->content = new_content;
memcpy(response->content + response->length, data, total);
response->content[response->length + total] = '\0';
response->length += total;