summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@gnome.org>2024-10-01 13:15:15 +0100
committerPhilip Withnall <pwithnall@gnome.org>2024-10-01 13:15:15 +0100
commitdf8592268ab1d458007e20b46ce982fdcc1bad5d (patch)
treeb16cebd9ccc6efc52ca84a606eebb1988ebb4ef7
parente4f5c2e9c5537d8db09334b2d8551b57ca5577f3 (diff)
gbytes: Add an assertion to placate static analysis
Otherwise `scan-build` thinks it’s possible for the `GBytes` to be double-freed, which would indeed happen if `try_steal_and_unref()` were to return `NULL` on this branch. It’s not actually possible for it to return `NULL` here though, as if `bytes->data` were `NULL`, the function would have already returned higher up. Fixes this `scan-build` failure: https://gitlab.gnome.org/GNOME/glib/-/jobs/4359929 Signed-off-by: Philip Withnall <pwithnall@gnome.org>
-rw-r--r--glib/gbytes.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/glib/gbytes.c b/glib/gbytes.c
index 5c844899f..73bfd1db0 100644
--- a/glib/gbytes.c
+++ b/glib/gbytes.c
@@ -490,6 +490,7 @@ try_steal_and_unref (GBytes *bytes,
{
*size = bytes->size;
result = (gpointer)bytes->data;
+ g_assert (result != NULL); /* otherwise the case of @bytes being freed can’t be distinguished */
g_free (bytes);
return result;
}