[libvirt] [PATCH 04/19] virsh: Reimplement _vshCalloc using g_malloc0_n

Peter Krempa pkrempa at redhat.com
Thu Oct 24 13:56:22 UTC 2019


Drop the dead code by using glib's allocator.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tools/vsh.c | 12 ++----------
 tools/vsh.h |  5 +----
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 3f8b7f2186..58ee94b52f 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -129,17 +129,9 @@ _vshMalloc(vshControl *ctl, size_t size, const char *filename, int line)
 }

 void *
-_vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filename,
-           int line)
+vshCalloc(vshControl *ctl G_GNUC_UNUSED, size_t nmemb, size_t size)
 {
-    char *x;
-
-    if (!xalloc_oversized(nmemb, size) &&
-        VIR_ALLOC_N(x, nmemb * size) == 0)
-        return x;
-    vshError(ctl, _("%s: %d: failed to allocate %d bytes"),
-             filename, line, (int) (size*nmemb));
-    exit(EXIT_FAILURE);
+    return g_malloc0_n(nmemb, size);
 }

 int
diff --git a/tools/vsh.h b/tools/vsh.h
index ad783e24b7..b6ac070f10 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -468,10 +468,7 @@ char * vshReadline(vshControl *ctl, const char *prompt);
 void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
 #define vshMalloc(_ctl, _sz)    _vshMalloc(_ctl, _sz, __FILE__, __LINE__)

-void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz,
-                 const char *filename, int line);
-#define vshCalloc(_ctl, _nmemb, _sz) \
-    _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__)
+void *vshCalloc(vshControl *ctl, size_t nmemb, size_t sz);

 /* Macros to help dealing with mutually exclusive options. */

-- 
2.21.0




More information about the libvir-list mailing list