# Avoid raw malloc and free, except in documentation comments.
sc_prohibit_raw_allocation:
- @prohibit='^.[^*].*\<((m|c|re)alloc|free) *\([^)]' \
- halt='use VIR_ macros from viralloc.h instead of malloc/free' \
+ @prohibit='^.[^*].*\<((m|c|re)alloc|free|g_malloc) *\([^)]' \
+ halt='use g_new0/g_malloc0/g_free instead of malloc/free/g_malloc' \
$(_sc_search_regexp)
# Avoid functions that can lead to double-close bugs.
virPCIVPDResource *res)
{
/* A buffer of up to one resource record field size (plus a zero byte) is needed. */
- g_autofree uint8_t *buf = g_malloc0(PCI_VPD_MAX_FIELD_SIZE + 1);
+ g_autofree uint8_t *buf = g_new0(uint8_t, PCI_VPD_MAX_FIELD_SIZE + 1);
uint16_t fieldDataLen = 0, bytesToRead = 0;
uint16_t fieldPos = resPos;
bool hasChecksum = false;
break;
case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_BINARY:
- fieldValue = g_malloc(fieldDataLen);
+ fieldValue = g_new0(char, fieldDataLen);
memcpy(fieldValue, buf, fieldDataLen);
break;
g_autofree char *resValue = NULL;
/* The resource value is not NULL-terminated so add one more byte. */
- g_autofree char *buf = g_malloc0(resDataLen + 1);
+ g_autofree char *buf = g_new0(char, resDataLen + 1);
if (virPCIVPDReadVPDBytes(vpdFileFd, (uint8_t *)buf, resDataLen, resPos, csum) < 0)
return -1;
gboolean rc;
guint8 *val;
- val = g_malloc(size);
+ val = g_new0(guint8, size);
start = xdr_getpos(xdrs);
if ((rc = xdr_opaque(xdrs, (caddr_t)val, size))) {
gint len = xdr_getpos(xdrs) - start;