}
-/**
- * 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
if (!*strptr)
return;
- virDispose(strptr, strlen(*strptr), sizeof(char), NULL);
+ memset(*strptr, 0, strlen(*strptr));
+ g_clear_pointer(strptr, g_free);
}
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);
#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
*/
#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)