]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: viralloc: Remove VIR_DISPOSE(_N)
authorPeter Krempa <pkrempa@redhat.com>
Mon, 1 Feb 2021 13:18:25 +0000 (14:18 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 3 Feb 2021 12:07:13 +0000 (13:07 +0100)
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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/libvirt_private.syms
src/util/viralloc.c
src/util/viralloc.h

index fa0c0887e9cdc45353da8b07a126358e13933117..62a7b8f7b93219fd1e7219939627606477794704 100644 (file)
@@ -1726,7 +1726,6 @@ vir_g_strdup_vprintf;
 # util/viralloc.h
 virAllocVar;
 virDeleteElementsN;
-virDispose;
 virDisposeString;
 virExpandN;
 virInsertElementsN;
index 0360b8a8aac738eaee254717ddbe0fb94dcc20b0..036007cb53122401df9eeec14a012eeba5c7c7fc 100644 (file)
@@ -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);
 }
index 1abd94fac45663367eb3a35ae2c2ea0c600e7e8b..0173107b87b75da38c055d8fc9c5b3f4a371cb84 100644 (file)
@@ -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)