[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[fedora-virt] [PATCH] don't dereference or free undefined "msg" upon OOM



Hi Rich,

Here's a tiny patch to prevent misbehavior on an OOM failure:
I prefer the decl-after-stmt (c99) syntax, but if you're
not assuming that already, just move the declaration of err "up".

>From bb57a823975019ab1be6f5f88e8276b53e8b4023 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering redhat com>
Date: Wed, 1 Jul 2009 15:45:01 +0200
Subject: [PATCH] don't dereference or free undefined "msg" upon OOM

* src/guestfs.c (guestfs_error): Handle failing vasprintf.
---
 src/guestfs.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/guestfs.c b/src/guestfs.c
index 5743a07..87b0d86 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -404,9 +404,11 @@ guestfs_error (guestfs_h *g, const char *fs, ...)
   char *msg;

   va_start (args, fs);
-  vasprintf (&msg, fs, args);
+  int err = vasprintf (&msg, fs, args);
   va_end (args);

+  if (err < 0) return;
+
   if (g->error_cb) g->error_cb (g, g->error_cb_data, msg);
   set_last_error (g, msg);

--
1.6.3.3.483.g4f5e


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]