On 07/04/13 14:06, Michal Privoznik wrote:
---

in src/util/virbitmap.c:

/**
 * virBitmapNew:
 * @size: number of bits
 *
 * Allocate a bitmap capable of containing @size bits.
 *
 * Returns a pointer to the allocated bitmap or NULL if
 * memory cannot be allocated.

This function historically returned only NULL without reporting the OOM error and the callers were supposed to do that. In multiple other patches you removed the call to reporting oom error, but:

 */
virBitmapPtr virBitmapNew(size_t size)
{
    virBitmapPtr bitmap;
    size_t sz;

    if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size || size == 0)
        return NULL;

... this condition will not report an error and thus the callers won't either.

    sz = (size + VIR_BITMAP_BITS_PER_UNIT - 1) /
          VIR_BITMAP_BITS_PER_UNIT;

    if (VIR_ALLOC(bitmap) < 0)
        return NULL;

But here it will be correct.

    if (VIR_ALLOC_N(bitmap->map, sz) < 0) {
        VIR_FREE(bitmap);
        return NULL;
    }

    bitmap->max_bit = size;
    bitmap->map_len = sz;
    return bitmap;
}

You need to adapt this function to explicitly call virReportOOMError in the place above and note that in the docs.

Peter


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to