Plumb out ownership a bit.

This commit is contained in:
2025-04-13 00:42:25 -04:00
parent 7e03da3251
commit c18a12d223

View File

@ -134,7 +134,7 @@ const char *a_Url_hostname(const DilloUrl *u)
* Create a DilloUrl object and initialize it. * Create a DilloUrl object and initialize it.
* (buffer, scheme, authority, path, query and fragment). * (buffer, scheme, authority, path, query and fragment).
*/ */
static DilloUrl *Url_object_new(const char *uri_str) static std::unique_ptr< DilloUrl > Url_object_new(const char *uri_str)
{ {
char *s, *p; char *s, *p;
@ -170,7 +170,7 @@ static DilloUrl *Url_object_new(const char *uri_str)
s = p; s = p;
} else if (*s) { } else if (*s) {
url->authority = s; url->authority = s;
return url.release(); return url;
} }
} }
@ -180,7 +180,7 @@ static DilloUrl *Url_object_new(const char *uri_str)
s = p; s = p;
} else if (*s) { } else if (*s) {
url->path = s; url->path = s;
return url.release(); return url;
} }
p = strpbrk(s, "?#"); p = strpbrk(s, "?#");
@ -197,7 +197,7 @@ static DilloUrl *Url_object_new(const char *uri_str)
url->fragment = s; url->fragment = s;
} }
return url.release(); return url;
} }
/** /**
@ -228,7 +228,7 @@ static std::string Url_resolve_relative(const char *RelStr,
if (RelUrl->scheme == NULL) { if (RelUrl->scheme == NULL) {
/* only required when there's no <scheme> in RelStr */ /* only required when there's no <scheme> in RelStr */
BaseUrl.reset( Url_object_new(BaseStr) ); BaseUrl= Url_object_new(BaseStr);
} }
/* path empty && scheme and authority undefined */ /* path empty && scheme and authority undefined */
@ -360,7 +360,7 @@ static std::string Url_resolve_relative(const char *RelStr,
*/ */
DilloUrl* a_Url_new(const char *url_str, const char *base_url) DilloUrl* a_Url_new(const char *url_str, const char *base_url)
{ {
DilloUrl *url; std::unique_ptr< DilloUrl > url;
char *urlstr = (char *)url_str; /* auxiliary variable, don't free */ char *urlstr = (char *)url_str; /* auxiliary variable, don't free */
char *p, *str1 = NULL, *str2 = NULL; char *p, *str1 = NULL, *str2 = NULL;
std::string SolvedUrl; std::string SolvedUrl;
@ -429,7 +429,7 @@ DilloUrl* a_Url_new(const char *url_str, const char *base_url)
* URLs like "http://en.wikipedia.org:80" to "https://en.wikipedia.org:443". * URLs like "http://en.wikipedia.org:80" to "https://en.wikipedia.org:443".
*/ */
if (prefs.http_strict_transport_security && if (prefs.http_strict_transport_security &&
a_Hsts_require_https(a_Url_hostname(url))) { a_Hsts_require_https(a_Url_hostname(url.get()))) {
_MSG("url: HSTS transformation for %s.\n", url->url_string->str); _MSG("url: HSTS transformation for %s.\n", url->url_string->str);
switch_to_https = TRUE; switch_to_https = TRUE;
} else if (prefs.http_force_https) { } else if (prefs.http_force_https) {
@ -456,7 +456,7 @@ DilloUrl* a_Url_new(const char *url_str, const char *base_url)
url->url_string.reset(); url->url_string.reset();
} }
return url; return url.release();
} }
@ -465,9 +465,7 @@ DilloUrl* a_Url_new(const char *url_str, const char *base_url)
*/ */
DilloUrl* a_Url_dup(const DilloUrl *ori) DilloUrl* a_Url_dup(const DilloUrl *ori)
{ {
DilloUrl *url; auto url = Url_object_new(URL_STR_(ori));
url = Url_object_new(URL_STR_(ori));
dReturn_val_if_fail (url != NULL, NULL); dReturn_val_if_fail (url != NULL, NULL);
url->url_string = URL_STR(ori); url->url_string = URL_STR(ori);
@ -477,7 +475,7 @@ DilloUrl* a_Url_dup(const DilloUrl *ori)
url->illegal_chars = ori->illegal_chars; url->illegal_chars = ori->illegal_chars;
url->illegal_chars_spc = ori->illegal_chars_spc; url->illegal_chars_spc = ori->illegal_chars_spc;
url->data = ori->data; url->data = ori->data;
return url; return url.release();
} }
/** /**