From 7e03da3251c7905df9ad7007de6b969a6be3c309ec452f9ca8ddb31501aa203c Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 13 Apr 2025 00:36:26 -0400 Subject: [PATCH] Use RAII internally in the allocation function. Next to return unique_ptr itself! --- src/url.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/url.cc b/src/url.cc index b6188ef..aa86396 100644 --- a/src/url.cc +++ b/src/url.cc @@ -136,12 +136,11 @@ const char *a_Url_hostname(const DilloUrl *u) */ static DilloUrl *Url_object_new(const char *uri_str) { - DilloUrl *url; char *s, *p; dReturn_val_if_fail (uri_str != NULL, NULL); - url = new DilloUrl{}; + auto url = std::make_unique< DilloUrl >(); /* url->buffer is given a little extra room in case HSTS needs to transform * a URL string ending in ":80" to ":443". @@ -171,7 +170,7 @@ static DilloUrl *Url_object_new(const char *uri_str) s = p; } else if (*s) { url->authority = s; - return url; + return url.release(); } } @@ -181,7 +180,7 @@ static DilloUrl *Url_object_new(const char *uri_str) s = p; } else if (*s) { url->path = s; - return url; + return url.release(); } p = strpbrk(s, "?#"); @@ -198,7 +197,7 @@ static DilloUrl *Url_object_new(const char *uri_str) url->fragment = s; } - return url; + return url.release(); } /**