From 51047f212ed9318d239b21dfa3f4c62ee5f948328f6b29cd905f428782f02183 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Mon, 14 Apr 2025 05:03:35 -0400 Subject: [PATCH] Another quick win on ownership. --- src/form.cc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/form.cc b/src/form.cc index 49cbea4..398e769 100644 --- a/src/form.cc +++ b/src/form.cc @@ -91,7 +91,7 @@ class DilloHtmlForm { bool showing_hiddens; bool enabled; void eventHandler(Resource *resource, EventButton *event); - DilloUrl *buildQueryUrl(DilloHtmlInput *active_input); + std::unique_ptr< DilloUrl > buildQueryUrl(DilloHtmlInput *active_input); std::optional< std::string > buildQueryData(DilloHtmlInput *active_submit); char *makeMultipartBoundary(iconv_t char_encoder, DilloHtmlInput *active_submit); @@ -1060,20 +1060,19 @@ void DilloHtmlForm::submit(DilloHtmlInput *active_input, EventButton *event) return; } - DilloUrl *url = buildQueryUrl(active_input); + auto url = buildQueryUrl(active_input); if (url) { if (event && event->button == 2) { if (prefs.middle_click_opens_new_tab) { int focus = prefs.focus_new_tab ? 1 : 0; if (event->state == SHIFT_MASK) focus = !focus; - a_UIcmd_open_url_nt(html->bw, url, focus); + a_UIcmd_open_url_nt(html->bw, url.get(), focus); } else { - a_UIcmd_open_url_nw(html->bw, url); + a_UIcmd_open_url_nw(html->bw, url.get()); } } else { - a_UIcmd_open_url(html->bw, url); + a_UIcmd_open_url(html->bw, url.get()); } - delete url; } } @@ -1081,9 +1080,9 @@ void DilloHtmlForm::submit(DilloHtmlInput *active_input, EventButton *event) * Build a new query URL. * (Called by submit()) */ -DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) +std::unique_ptr< DilloUrl > DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) { - DilloUrl *new_url = NULL; + std::unique_ptr< DilloUrl > new_url; if ((method == DILLO_HTML_METHOD_GET) || (method == DILLO_HTML_METHOD_POST)) { @@ -1107,12 +1106,12 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) char *action_str = dStrdup(URL_STR(action)); if (method == DILLO_HTML_METHOD_POST) { - new_url = a_Url_new(action_str, NULL).release(); + new_url = a_Url_new(action_str, NULL); /* new_url keeps the dStr and sets DataStr to NULL */ - a_Url_set_data(new_url, DataStr); - a_Url_set_flags(new_url, URL_FLAGS(new_url) | URL_Post); + a_Url_set_data(new_url.get(), DataStr); + a_Url_set_flags(new_url.get(), URL_FLAGS(new_url.get()) | URL_Post); if (content_type == DILLO_HTML_ENC_MULTIPART) - a_Url_set_flags(new_url, URL_FLAGS(new_url) | URL_MultipartEnc); + a_Url_set_flags(new_url.get(), URL_FLAGS(new_url.get()) | URL_MultipartEnc); } else { /* remove and sections if present */ char *url_str, *p; @@ -1122,8 +1121,8 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) *p = 0; url_str = dStrconcat(action_str, "?", DataStr.c_str(), NULL); - new_url = a_Url_new(url_str, NULL).release(); - a_Url_set_flags(new_url, URL_FLAGS(new_url) | URL_Get); + new_url = a_Url_new(url_str, NULL); + a_Url_set_flags(new_url.get(), URL_FLAGS(new_url.get()) | URL_Get); dFree(url_str); } dFree(action_str);