From 930e47faebd878fe29cfabe80286189f9113a58b Mon Sep 17 00:00:00 2001
From: Mole Shang <135e2@135e2.dev>
Date: Mon, 7 Aug 2023 20:25:10 +0800
Subject: process_url: free malloc'd data

---
 src/process_url.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

(limited to 'src')

diff --git a/src/process_url.c b/src/process_url.c
index bba3c53..b6fa730 100644
--- a/src/process_url.c
+++ b/src/process_url.c
@@ -20,8 +20,8 @@
 #include "extractors/extractor.h"
 #include "logger.h"
 #include "process_url.h"
-#include "utils/utils.h"
 #include "utils/types.h"
+#include "utils/utils.h"
 
 /* NOTICE: the global curl_conf pointer will only stay valid during downloading,
  * otherwise, ALWAYS point it to NULL. */
@@ -497,12 +497,12 @@ void poll_status(status_t *stat) {
         thrd_join(tid[i], &r);
       }
       merge_and_cleanup(curl_conf);
+      append_log("Download %s finished.\n", curl_conf->outfn);
       // Perform the callback
       if (is_empty_queue(&dl_queue) && callback_g) {
         callback_g(p_callback_struct_g);
       }
-      append_log("Download %s finished.\n", curl_conf->outfn);
-      curl_conf = NULL;
+      free_and_nullify(curl_conf);
     }
     mtx_unlock(&mtx);
   }
@@ -520,6 +520,7 @@ int get(const char *URL, char **pdstr) {
   CURLcode res = logerr(curl_easy_perform(curl));
   *pdstr = malloc(pagedata.len + 1);
   strcpy(*pdstr, pagedata.string);
+  free_and_nullify(pagedata.string);
   curl_easy_cleanup(curl);
   return res;
 }
-- 
cgit v1.2.3