diff options
author | Philip Withnall <pwithnall@endlessos.org> | 2023-04-13 13:03:01 +0100 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2023-04-13 13:03:01 +0100 |
commit | 62a8ac3240acf74c2be336920820a92cf7bf86c3 (patch) | |
tree | 84d3bd89723eabf0a5680a4743243f64bd158ed2 /examples/simple-httpd.c | |
parent | b9f4f0367704e4d7f6004645c24887a979014f10 (diff) | |
download | libsoup-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 'examples/simple-httpd.c')
-rw-r--r-- | examples/simple-httpd.c | 7 |
1 files changed, 5 insertions, 2 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; } |