summaryrefslogtreecommitdiff
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
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>
-rw-r--r--examples/simple-httpd.c7
-rw-r--r--tests/forms-test.c14
2 files changed, 15 insertions, 6 deletions
diff --git a/examples/simple-httpd.c b/examples/simple-httpd.c
index ac2c2e54..10afda65 100644
--- a/examples/simple-httpd.c
+++ b/examples/simple-httpd.c
@@ -88,6 +88,8 @@ do_get (SoupServer *server, SoupServerMessage *msg, const char *path)
if (g_file_test (path, G_FILE_TEST_IS_DIR)) {
GString *listing;
char *index_path;
+ char *listing_str;
+ gsize listing_len;
slash = strrchr (path, '/');
if (!slash || slash[1]) {
@@ -109,11 +111,12 @@ do_get (SoupServer *server, SoupServerMessage *msg, const char *path)
g_free (index_path);
listing = get_directory_listing (path);
+ listing_len = listing->len;
+ listing_str = g_string_free (g_steal_pointer (&listing), FALSE);
soup_server_message_set_response (msg, "text/html",
SOUP_MEMORY_TAKE,
- listing->str, listing->len);
+ g_steal_pointer (&listing_str), listing_len);
soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
- g_string_free (listing, FALSE);
return;
}
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);
}