summaryrefslogtreecommitdiff
path: root/tests/forms-test.c
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@endlessos.org>2023-04-13 13:03:01 +0100
committerPhilip Withnall <pwithnall@endlessos.org>2023-04-13 13:03:01 +0100
commit62a8ac3240acf74c2be336920820a92cf7bf86c3 (patch)
tree84d3bd89723eabf0a5680a4743243f64bd158ed2 /tests/forms-test.c
parentb9f4f0367704e4d7f6004645c24887a979014f10 (diff)
downloadlibsoup-62a8ac3240acf74c2be336920820a92cf7bf86c3.tar.gz
tests: Fix warnings about unused results from g_string_free()
GLib 2.76 emits a warning if `g_string_free (_, FALSE)` is used without using its return value, as it typically signifies a leak: ``` warning: ignoring return value of ‘g_string_free_and_steal’ declared with attribute ‘warn_unused_result’ [-Wunused-result] ``` In this case, the libsoup example and test code did *not* leak because it had already stolen the string data from `GString`. That’s a bit of a layering violation (the string data briefly has two owners), so rearrange the code to fix that and silence the warning. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Diffstat (limited to 'tests/forms-test.c')
-rw-r--r--tests/forms-test.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/tests/forms-test.c b/tests/forms-test.c
index 201ad454..a1af7b30 100644
--- a/tests/forms-test.c
+++ b/tests/forms-test.c
@@ -311,6 +311,8 @@ hello_callback (SoupServer *server,
const char *content_type;
GString *buf;
const char *method;
+ char *buf_str;
+ gsize buf_len;
method = soup_server_message_get_method (msg);
if (method != SOUP_METHOD_GET && method != SOUP_METHOD_HEAD) {
@@ -351,10 +353,11 @@ hello_callback (SoupServer *server,
}
}
+ buf_len = buf->len;
+ buf_str = g_string_free (g_steal_pointer (&buf), FALSE);
soup_server_message_set_response (msg, content_type,
SOUP_MEMORY_TAKE,
- buf->str, buf->len);
- g_string_free (buf, FALSE);
+ g_steal_pointer (&buf_str), buf_len);
soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
}
@@ -368,6 +371,8 @@ md5_get_callback (SoupServer *server,
const char *file = NULL, *md5sum = NULL, *fmt;
const char *content_type;
GString *buf;
+ char *buf_str;
+ gsize buf_len;
if (query) {
file = g_hash_table_lookup (query, "file");
@@ -397,10 +402,11 @@ md5_get_callback (SoupServer *server,
g_string_append_printf (buf, "%s", md5sum);
}
+ buf_len = buf->len;
+ buf_str = g_string_free (g_steal_pointer (&buf), FALSE);
soup_server_message_set_response (msg, content_type,
SOUP_MEMORY_TAKE,
- buf->str, buf->len);
- g_string_free (buf, FALSE);
+ g_steal_pointer (&buf_str), buf_len);
soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
}