mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
handle failed memory allocations
This commit is contained in:
parent
c77d34ee3a
commit
1b33e2d104
3 changed files with 18 additions and 0 deletions
|
@ -285,6 +285,9 @@ int vfio_device_attach(struct vfio_device *d, struct vfio_container *c, const ch
|
|||
d->regions = new struct vfio_region_info[d->info.num_regions];
|
||||
d->mappings = new void *[d->info.num_regions];
|
||||
|
||||
if (!d->irqs || !d->regions || !d->mappsings)
|
||||
throw RuntimeError("Failed to allocate memory!");
|
||||
|
||||
/* Get device regions */
|
||||
for (int i = 0; i < d->info.num_regions && i < 8; i++) {
|
||||
struct vfio_region_info *region = &d->regions[i];
|
||||
|
@ -328,6 +331,9 @@ int vfio_pci_reset(struct vfio_device *d)
|
|||
struct vfio_pci_hot_reset_info *reset_info = new char[reset_info_len];
|
||||
struct vfio_pci_hot_reset *reset = new char[reset_len];
|
||||
|
||||
if (!reset_info || !reset)
|
||||
throw RuntimeError("Failed to allocate memory!");
|
||||
|
||||
reset_info->argsz = reset_info_len;
|
||||
reset->argsz = reset_len;
|
||||
|
||||
|
@ -405,6 +411,8 @@ int vfio_pci_msi_deinit(struct vfio_device *d, int efds[32])
|
|||
|
||||
irq_setlen = sizeof(struct vfio_irq_set) + sizeof(int) * irq_count;
|
||||
irq_set = new char[irq_setlen];
|
||||
if (!irq_set)
|
||||
throw RuntimeError("Failed to allocate memory!");
|
||||
|
||||
irq_set->argsz = irq_setlen;
|
||||
irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
|
||||
|
@ -439,6 +447,8 @@ int vfio_pci_msi_init(struct vfio_device *d, int efds[32])
|
|||
|
||||
irq_setlen = sizeof(struct vfio_irq_set) + sizeof(int) * irq_count;
|
||||
irq_set = new char[irq_setlen];
|
||||
if (!irq_set)
|
||||
throw RuntimeError("Failed to allocate memory!");
|
||||
|
||||
irq_set->argsz = irq_setlen;
|
||||
irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | VFIO_IRQ_SET_ACTION_TRIGGER;
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <villas/config.h>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/colors.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/log.hpp>
|
||||
|
||||
static pthread_t main_thread;
|
||||
|
@ -260,6 +261,8 @@ char * vstrf(const char *fmt, va_list va)
|
|||
void * memdup(const void *src, size_t bytes)
|
||||
{
|
||||
void *dst = new char[bytes];
|
||||
if (!dst)
|
||||
throw RuntimeError("Failed to allocate memory!");
|
||||
|
||||
memcpy(dst, src, bytes);
|
||||
|
||||
|
|
|
@ -24,9 +24,12 @@
|
|||
#include <cstring>
|
||||
#include <criterion/criterion.h>
|
||||
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/list.h>
|
||||
|
||||
using namespace villas;
|
||||
|
||||
static const char *nouns[] = { "time", "person", "year", "way", "day", "thing", "man", "world", "life", "hand", "part", "child", "eye", "woman", "place", "work", "week", "case", "point", "government", "company", "number", "group", "problem", "fact" };
|
||||
|
||||
struct data {
|
||||
|
@ -45,6 +48,8 @@ Test(list, vlist_lookup)
|
|||
|
||||
for (unsigned i = 0; i < ARRAY_LEN(nouns); i++) {
|
||||
struct data *d = new struct data;
|
||||
if (!d)
|
||||
throw RuntimeError("Failed to allocate memory!");
|
||||
|
||||
d->tag = nouns[i];
|
||||
d->data = i;
|
||||
|
|
Loading…
Add table
Reference in a new issue