[glib: 1/2] gprintf: Avoid an infinite loop on ENOMEM in g_vasprintf()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] gprintf: Avoid an infinite loop on ENOMEM in g_vasprintf()
- Date: Thu, 20 Oct 2022 12:29:22 +0000 (UTC)
commit b204b46fc0c1a36b327eb5979a5ae6297dc5d049
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu Oct 13 13:53:11 2022 +0100
gprintf: Avoid an infinite loop on ENOMEM in g_vasprintf()
Instead of going through the normal error logging code, which does
further allocations and will potentially call back into `g_vasprintf()`
and create an infinite loop, just `fputs()` an error message and abort.
If we’re getting `ENOMEM` the process is doomed anyway.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Fixes: #2753
glib/gprintf.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/glib/gprintf.c b/glib/gprintf.c
index 818a55ad25..10b4365336 100644
--- a/glib/gprintf.c
+++ b/glib/gprintf.c
@@ -342,7 +342,14 @@ g_vasprintf (gchar **string,
if (len < 0)
{
if (saved_errno == ENOMEM)
- g_error ("%s: failed to allocate memory", G_STRLOC);
+ {
+ /* Try and print a message to be a bit helpful, but stick to the
+ * bare minimum to avoid any code path which could try and fail to
+ * allocate additional memory. */
+ fputs (G_STRLOC, stderr);
+ fputs (": failed to allocate memory\n", stderr);
+ g_abort ();
+ }
else
*string = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]