summaryrefslogtreecommitdiff
path: root/src/process_url.c
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2024-03-02 12:55:03 +0800
committerMole Shang <[email protected]>2024-03-02 12:55:03 +0800
commit74ebee5d3a81a39766ba8cd436a548449ea887b0 (patch)
tree69c238d2bff0d69aa4778d22e21de8d519b00dff /src/process_url.c
parent62c193bd4e464ec9d847b8abff21e10dfc7b511e (diff)
downloadhinata-74ebee5d3a81a39766ba8cd436a548449ea887b0.tar.gz
hinata-74ebee5d3a81a39766ba8cd436a548449ea887b0.tar.bz2
hinata-74ebee5d3a81a39766ba8cd436a548449ea887b0.zip
tree-wide: use FREE_AND_NULLIFY macro and reformat code
Jeez idk why i forgot the pass-by-value feature, so the original version never gets the pointer nullified. Fix it by using our favourite C-style macro.
Diffstat (limited to 'src/process_url.c')
-rw-r--r--src/process_url.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/process_url.c b/src/process_url.c
index c1d8d38..00bc696 100644
--- a/src/process_url.c
+++ b/src/process_url.c
@@ -1,4 +1,5 @@
#include "constants.h"
+#include "status.h"
#include <curl/curl.h>
#include <curl/easy.h>
#include <curl/header.h>
@@ -231,7 +232,7 @@ static int parse_url(const char *URL, const char *outdir, char *fn) {
} else {
curl_c->outfn = malloc(strlen(outdir) + strlen(fn) + 2);
gen_fullpathfn(curl_c->outfn, outdir, fn);
- free_and_nullify(fn);
+ FREE_AND_NULLIFY(fn);
}
DEBUG_PRINT("File will be saved as: %s\n", curl_c->outfn);
DEBUG_PRINT("Got regular URL: %s\n", curl_c->URL);
@@ -389,9 +390,8 @@ static int merge_and_cleanup(curl_conf_t *curl_c) {
// Reset stat
curl_c->success_thrd = 0;
curl_c->total_thrd = 0;
- free_and_nullify(curl_c->URL);
- free_and_nullify(curl_c->outfn);
- free_and_nullify(curl_c);
+ FREE_AND_NULLIFY(curl_c->URL);
+ FREE_AND_NULLIFY(curl_c->outfn);
return 0;
}
@@ -460,7 +460,7 @@ static char *callback_struct_convert_fullpath(char **p_filename) {
char *tmp = malloc(strlen(outdir_g) + strlen(*p_filename) + 2);
replace_illegal_char(*p_filename);
gen_fullpathfn(tmp, outdir_g, *p_filename);
- free_and_nullify(*p_filename);
+ FREE_AND_NULLIFY(*p_filename);
return tmp;
}
@@ -469,7 +469,7 @@ void add_cookie(char **p_cookie) {
if (cookie_g) {
char *tmp = malloc(strlen(cookie_g) + strlen(cookie) + 3);
sprintf(tmp, "%s; %s", cookie_g, cookie);
- free_and_nullify(cookie_g);
+ FREE_AND_NULLIFY(cookie_g);
cookie_g = tmp;
} else {
cookie_g = cookie;
@@ -506,7 +506,7 @@ void curl_cleanup(status_t *stat) {
cnd_destroy(&cnd);
}
free_queue(&dl_queue);
- free_and_nullify(cookie_g);
+ FREE_AND_NULLIFY(cookie_g);
curl_url_cleanup(h);
curl_global_cleanup();
}
@@ -544,6 +544,7 @@ void poll_status(status_t *stat) {
thrd_join(tid[i], &r);
}
merge_and_cleanup(curl_conf);
+ FREE_AND_NULLIFY(curl_conf);
// Perform the callback
if (is_empty_queue(&dl_queue) && callback_g && !corrupted) {
thrd_t cb_thrd;
@@ -568,7 +569,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);
+ FREE_AND_NULLIFY(pagedata.string);
curl_easy_cleanup(curl);
return res;
}