From 98888e6070a64e291914164cc1a0af5e3df2b0c2 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Fri, 12 Mar 2021 17:36:08 +0100 Subject: [PATCH] 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. --- lib/cookie.c | 8 ++++---- 1 file 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; }