util: viralloc: Remove VIR_DISPOSE(_N)

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>
This commit is contained in:
Peter Krempa 2021-02-01 14:18:25 +01:00
parent f08fea10fb
commit bacf612607
3 changed files with 2 additions and 65 deletions

View File

@ -1726,7 +1726,6 @@ vir_g_strdup_vprintf;
# util/viralloc.h # util/viralloc.h
virAllocVar; virAllocVar;
virDeleteElementsN; virDeleteElementsN;
virDispose;
virDisposeString; virDisposeString;
virExpandN; virExpandN;
virInsertElementsN; virInsertElementsN;

View 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: * virDisposeString:
* @ptrptr: pointer to pointer for a string which should be sanitized and cleared * @ptrptr: pointer to pointer for a string which should be sanitized and cleared
@ -343,5 +307,6 @@ virDisposeString(char **strptr)
if (!*strptr) if (!*strptr)
return; return;
virDispose(strptr, strlen(*strptr), sizeof(char), NULL); memset(*strptr, 0, strlen(*strptr));
g_clear_pointer(strptr, g_free);
} }

View 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) int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, size_t count)
G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1); 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) void virDisposeString(char **strptr)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
@ -342,20 +340,6 @@ void virDisposeString(char **strptr)
#define VIR_FREE(ptr) g_clear_pointer(&(ptr), g_free) #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: * VIR_DISPOSE_STRING:
* @ptr: pointer to a string to be cleared and freed * @ptr: pointer to a string to be cleared and freed
@ -375,14 +359,3 @@ void virDisposeString(char **strptr)
*/ */
#define VIR_AUTODISPOSE_STR \ #define VIR_AUTODISPOSE_STR \
__attribute__((cleanup(virDisposeString))) char * __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)