diff options
author | Daniel Gustafsson <daniel@yesql.se> | 2021-03-12 17:36:08 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-05-11 08:45:17 +0200 |
commit | 98888e6070a64e291914164cc1a0af5e3df2b0c2 (patch) | |
tree | 84a6c3a06d905494b19f2abe0e8c70d22d65e15e /lib/cookie.c | |
parent | 54bd65cabd6ac619fe4ea25e2746e0117f89f170 (diff) | |
download | curl-98888e6070a64e291914164cc1a0af5e3df2b0c2.tar.gz |
cookies: make use of string duplication function
strstore() is defined as a strdup which ensures to free the target
pointer before duping the source char * into it. Make use of it in
two more cases where it can simplify the code.
Diffstat (limited to 'lib/cookie.c')
-rw-r--r-- | lib/cookie.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/cookie.c b/lib/cookie.c index 082a32f4c..e0e5cf99b 100644 --- a/lib/cookie.c +++ b/lib/cookie.c @@ -105,6 +105,8 @@ Example set of cookies: #include "curl_memory.h" #include "memdebug.h" +static void strstore(char **str, const char *newstr); + static void freecookie(struct Cookie *co) { free(co->expirestr); @@ -197,8 +199,7 @@ static bool pathmatch(const char *cookie_path, const char *request_uri) /* #-fragments are already cut off! */ if(0 == strlen(uri_path) || uri_path[0] != '/') { - free(uri_path); - uri_path = strdup("/"); + strstore(&uri_path, "/"); if(!uri_path) return FALSE; } @@ -333,8 +334,7 @@ static char *sanitize_cookie_path(const char *cookie_path) /* RFC6265 5.2.4 The Path Attribute */ if(new_path[0] != '/') { /* Let cookie-path be the default-path. */ - free(new_path); - new_path = strdup("/"); + strstore(&new_path, "/"); return new_path; } |