]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cookies: make use of string duplication function
authorDaniel Gustafsson <daniel@yesql.se>
Fri, 12 Mar 2021 16:36:08 +0000 (17:36 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 11 May 2021 06:45:17 +0000 (08:45 +0200)
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.

lib/cookie.c

index 082a32f4cb8e1b8aa4e44fe6e70c8ff52b4b5e97..e0e5cf99b8bbdf970df91dea10f4b6f7ca3d03e2 100644 (file)
@@ -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;
   }