]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Reimplement _vshCalloc using g_malloc0_n
authorPeter Krempa <pkrempa@redhat.com>
Thu, 24 Oct 2019 07:02:24 +0000 (09:02 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 24 Oct 2019 17:35:34 +0000 (19:35 +0200)
Drop the dead code by using glib's allocator.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/vsh.c
tools/vsh.h

index ec46b822c586dc485b7753c72379a6b02312fe60..89ba9a487fc54b1926aed7a8843e1c0b820727d8 100644 (file)
@@ -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
index ad783e24b7e5f7fd203c1159071d6263c4dbaddb..b6ac070f10574a0d1fb112a1e32ebeb32d1963ad 100644 (file)
@@ -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. */