[PATCH 14/14] util: viralloc: Remove VIR_DISPOSE(_N)

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

 



The macros are unused now and callers who care about clearing the memory
they use should use memset() appropriately.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 -
 src/util/viralloc.c      | 39 ++-------------------------------------
 src/util/viralloc.h      | 27 ---------------------------
 3 files changed, 2 insertions(+), 65 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8138780237..45e89eba3c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1726,7 +1726,6 @@ vir_g_strdup_vprintf;
 # util/viralloc.h
 virAllocVar;
 virDeleteElementsN;
-virDispose;
 virDisposeString;
 virExpandN;
 virInsertElementsN;
diff --git a/src/util/viralloc.c b/src/util/viralloc.c
index 0360b8a8aa..036007cb53 100644
--- a/src/util/viralloc.c
+++ b/src/util/viralloc.c
@@ -295,42 +295,6 @@ int virAllocVar(void *ptrptr,
 }


-/**
- * virDispose:
- * @ptrptr: pointer to pointer for address of memory to be sanitized and freed
- * @count: count of elements in the array to dispose
- * @element_size: size of one element
- * @countptr: pointer to the count variable to clear (may be NULL)
- *
- * Clear and release the chunk of memory in the pointer pointed to by 'prtptr'.
- *
- * If @countptr is provided, it's value is used instead of @count and it's set
- * to 0 after clearing and freeing the memory.
- *
- * After release, 'ptrptr' will be updated to point to NULL.
- */
-void virDispose(void *ptrptr,
-                size_t count,
-                size_t element_size,
-                size_t *countptr)
-{
-    int save_errno = errno;
-
-    if (countptr)
-        count = *countptr;
-
-    if (*(void**)ptrptr && count > 0)
-        memset(*(void **)ptrptr, 0, count * element_size);
-
-    g_free(*(void**)ptrptr);
-    *(void**)ptrptr = NULL;
-
-    if (countptr)
-        *countptr = 0;
-    errno = save_errno;
-}
-
-
 /**
  * virDisposeString:
  * @ptrptr: pointer to pointer for a string which should be sanitized and cleared
@@ -343,5 +307,6 @@ virDisposeString(char **strptr)
     if (!*strptr)
         return;

-    virDispose(strptr, strlen(*strptr), sizeof(char), NULL);
+    memset(*strptr, 0, strlen(*strptr));
+    g_clear_pointer(strptr, g_free);
 }
diff --git a/src/util/viralloc.h b/src/util/viralloc.h
index 1abd94fac4..0173107b87 100644
--- a/src/util/viralloc.h
+++ b/src/util/viralloc.h
@@ -52,8 +52,6 @@ int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr,
 int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count)
     G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1);

-void virDispose(void *ptrptr, size_t count, size_t element_size, size_t *countptr)
-    ATTRIBUTE_NONNULL(1);
 void virDisposeString(char **strptr)
     ATTRIBUTE_NONNULL(1);

@@ -342,20 +340,6 @@ void virDisposeString(char **strptr)
 #define VIR_FREE(ptr) g_clear_pointer(&(ptr), g_free)


-/**
- * VIR_DISPOSE_N:
- * @ptr: pointer holding address to be cleared and freed
- * @count: count of elements in @ptr
- *
- * Clear the memory of the array of elements pointed to by 'ptr' of 'count'
- * elements and free it. Update the pointer/count to NULL/0.
- *
- * This macro is safe to use on arguments with side effects.
- */
-#define VIR_DISPOSE_N(ptr, count) virDispose(1 ? (void *) &(ptr) : (ptr), 0, \
-                                             sizeof(*(ptr)), &(count))
-
-
 /**
  * VIR_DISPOSE_STRING:
  * @ptr: pointer to a string to be cleared and freed
@@ -375,14 +359,3 @@ void virDisposeString(char **strptr)
  */
 #define VIR_AUTODISPOSE_STR \
     __attribute__((cleanup(virDisposeString))) char *
-
-/**
- * VIR_DISPOSE:
- * @ptr: pointer to memory to be cleared and freed
- *
- * Clears and frees the corresponding memory.
- *
- * This macro is safe to be used on arguments with side effects.
- */
-#define VIR_DISPOSE(ptr) virDispose(1 ? (void *) &(ptr) : (ptr), 1, \
-                                    sizeof(*(ptr)), NULL)
-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux