mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
add more nullptr checks after memory allocations
This commit is contained in:
parent
c71cb752fc
commit
8e259516a3
41 changed files with 162 additions and 31 deletions
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit 7fcce77ddb6ae13a6da87e13186d3ab2a05945eb
|
||||
Subproject commit 0f179b26614289150dae091366943ab34014e069
|
|
@ -182,6 +182,8 @@ void Server::acceptNewSession() {
|
|||
int fd = ::accept(sd, nullptr, nullptr);
|
||||
|
||||
auto s = new sessions::Socket(api, fd);
|
||||
if (!s)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
pollfd pfd = {
|
||||
.fd = fd,
|
||||
|
|
|
@ -49,6 +49,9 @@ Http::Http(Api *a, lws *w) :
|
|||
throw RuntimeError("Invalid request");
|
||||
|
||||
uri = new char[hdrlen + 1];
|
||||
if (!uri)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
lws_hdr_copy(wsi, uri, hdrlen + 1, options ? WSI_TOKEN_OPTIONS_URI : WSI_TOKEN_POST_URI);
|
||||
|
||||
/* Parse request URI */
|
||||
|
|
|
@ -57,13 +57,21 @@ int protobuf_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct
|
|||
unsigned psz;
|
||||
|
||||
auto *pb_msg = new Villas__Node__Message;
|
||||
if (!pb_msg)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
villas__node__message__init(pb_msg);
|
||||
|
||||
pb_msg->n_samples = cnt;
|
||||
pb_msg->samples = new Villas__Node__Sample*[pb_msg->n_samples];
|
||||
if (!pb_msg->samples)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
for (unsigned i = 0; i < pb_msg->n_samples; i++) {
|
||||
Villas__Node__Sample *pb_smp = pb_msg->samples[i] = new Villas__Node__Sample;
|
||||
if (!pb_msg->samples[i])
|
||||
throw MemoryAllocationError();
|
||||
|
||||
villas__node__sample__init(pb_smp);
|
||||
|
||||
struct sample *smp = smps[i];
|
||||
|
@ -77,6 +85,9 @@ int protobuf_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct
|
|||
|
||||
if (io->flags & smp->flags & (int) SampleFlags::HAS_TS_ORIGIN) {
|
||||
pb_smp->timestamp = new Villas__Node__Timestamp;
|
||||
if (!pb_smp->timestamp)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
villas__node__timestamp__init(pb_smp->timestamp);
|
||||
|
||||
pb_smp->timestamp->sec = smp->ts.origin.tv_sec;
|
||||
|
@ -85,9 +96,14 @@ int protobuf_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct
|
|||
|
||||
pb_smp->n_values = smp->length;
|
||||
pb_smp->values = new Villas__Node__Value*[pb_smp->n_values];
|
||||
if (pb_msg->values)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
for (unsigned j = 0; j < pb_smp->n_values; j++) {
|
||||
Villas__Node__Value *pb_val = pb_smp->values[j] = new Villas__Node__Value;
|
||||
if (!pb_smp->values[i])
|
||||
throw MemoryAllocationError();
|
||||
|
||||
villas__node__value__init(pb_val);
|
||||
|
||||
enum SignalType fmt = sample_format(smp, j);
|
||||
|
@ -110,6 +126,8 @@ int protobuf_sprint(struct io *io, char *buf, size_t len, size_t *wbytes, struct
|
|||
case SignalType::COMPLEX:
|
||||
pb_val->value_case = VILLAS__NODE__VALUE__VALUE_Z;
|
||||
pb_val->z = new Villas__Node__Complex;
|
||||
if (!pb_val->z)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
villas__node__complex__init(pb_val->z);
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ public:
|
|||
fharmonics = new int[fharmonics_len];
|
||||
coeffs = new std::complex<double>[fharmonics_len];
|
||||
if (!fharmonics || !coeffs)
|
||||
throw RuntimeError("Failed to allocate memory");
|
||||
throw MemoryAllocationError();
|
||||
|
||||
json_array_foreach(json_harmonics, i, json_harmonic) {
|
||||
if (!json_is_integer(json_harmonic))
|
||||
|
|
|
@ -60,6 +60,9 @@ public:
|
|||
moving_avg = new int64_t[sz];
|
||||
moving_var = new int64_t[sz];
|
||||
|
||||
if (!jitter_val || !delay_series || !moving_avg || !moving_var)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
memset(jitter_val, 0, sz);
|
||||
memset(delay_series, 0, sz);
|
||||
memset(moving_avg, 0, sz);
|
||||
|
|
|
@ -126,6 +126,9 @@ public:
|
|||
readHook = new StatsReadHook(this, p, n, fl, prio, en);
|
||||
writeHook = new StatsWriteHook(this, p, n, fl, prio, en);
|
||||
|
||||
if (!readHook || !writeHook)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
if (node) {
|
||||
vlist_push(&node->in.hooks, (void *) readHook);
|
||||
vlist_push(&node->out.hooks, (void *) writeHook);
|
||||
|
|
|
@ -30,7 +30,9 @@
|
|||
#include <villas/format_type.h>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/sample.h>
|
||||
#include <villas/exceptions.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
static int io_print_lines(struct io *io, struct sample *smps[], unsigned cnt)
|
||||
|
@ -89,6 +91,8 @@ int io_init(struct io *io, const struct format_type *fmt, struct vlist *signals,
|
|||
|
||||
io->_vt = fmt;
|
||||
io->_vd = new char[fmt->size];
|
||||
if (!io->_vd)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
io->flags = flags | (io_type(io)->flags & ~(int) SampleFlags::HAS_ALL);
|
||||
io->delimiter = io_type(io)->delimiter ? io_type(io)->delimiter : '\n';
|
||||
|
@ -100,6 +104,9 @@ int io_init(struct io *io, const struct format_type *fmt, struct vlist *signals,
|
|||
io->in.buffer = new char[io->in.buflen];
|
||||
io->out.buffer = new char[io->out.buflen];
|
||||
|
||||
if (!io->in.buffer || !io->out.buffer)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
io->signals = signals;
|
||||
|
||||
ret = io_type(io)->init ? io_type(io)->init(io) : 0;
|
||||
|
@ -117,6 +124,8 @@ int io_init2(struct io *io, const struct format_type *fmt, const char *dt, int f
|
|||
struct vlist *signals;
|
||||
|
||||
signals = new struct vlist;
|
||||
if (!signals)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = vlist_init(signals);
|
||||
if (ret)
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <villas/node/config.h>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
|
||||
#include <villas/kernel/if.h>
|
||||
#include <villas/kernel/tc.h>
|
||||
|
@ -38,6 +39,7 @@
|
|||
|
||||
#include <villas/nodes/socket.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
int if_init(struct interface *i, struct rtnl_link *link)
|
||||
|
@ -162,7 +164,7 @@ struct interface * if_get_egress(struct sockaddr *sa, struct vlist *interfaces)
|
|||
/* If not found, create a new interface */
|
||||
i = new struct interface;
|
||||
if (!i)
|
||||
return nullptr;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = if_init(i, link);
|
||||
if (ret)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <villas/kernel/tc_netem.h>
|
||||
#include <villas/kernel/kernel.hpp>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
@ -273,6 +274,8 @@ int tc_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, json_t *json)
|
|||
size_t len = json_array_size(json);
|
||||
|
||||
int16_t *data = new int16_t[len];
|
||||
if (!data)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
json_array_foreach(json, idx, elm) {
|
||||
if (!json_is_integer(elm))
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <villas/sample.h>
|
||||
#include <villas/list.h>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/node.h>
|
||||
#include <villas/signal.h>
|
||||
|
||||
|
@ -217,6 +218,8 @@ int mapping_list_parse(struct vlist *ml, json_t *cfg, struct vlist *nodes)
|
|||
|
||||
json_array_foreach(json_mapping, i, json_entry) {
|
||||
auto *me = new struct mapping_entry;
|
||||
if (!me)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = mapping_parse(me, json_entry, nodes);
|
||||
if (ret)
|
||||
|
|
|
@ -24,7 +24,9 @@
|
|||
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/memory.h>
|
||||
#include <villas/exceptions.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
static struct memory_allocation * memory_heap_alloc(size_t len, size_t alignment, struct memory_type *m)
|
||||
|
@ -33,7 +35,7 @@ static struct memory_allocation * memory_heap_alloc(size_t len, size_t alignment
|
|||
|
||||
auto *ma = new struct memory_allocation;
|
||||
if (!ma)
|
||||
return nullptr;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ma->alignment = alignment;
|
||||
ma->type = m;
|
||||
|
|
|
@ -46,7 +46,7 @@ static struct memory_allocation * memory_ib_alloc(size_t len, size_t alignment,
|
|||
|
||||
auto *ma = new struct memory_allocation;
|
||||
if (!ma)
|
||||
return nullptr;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ma->type = m;
|
||||
ma->length = len;
|
||||
|
|
|
@ -33,7 +33,9 @@
|
|||
#include <villas/log.h>
|
||||
#include <villas/memory.h>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
static struct memory_allocation * memory_managed_alloc(size_t len, size_t alignment, struct memory_type *m)
|
||||
|
@ -108,7 +110,7 @@ static struct memory_allocation * memory_managed_alloc(size_t len, size_t alignm
|
|||
|
||||
auto *ma = new struct memory_allocation;
|
||||
if (!ma)
|
||||
return nullptr;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ma->address = cptr;
|
||||
ma->type = m;
|
||||
|
|
|
@ -39,7 +39,9 @@
|
|||
#include <villas/memory.h>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/kernel/kernel.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
|
@ -104,7 +106,7 @@ static struct memory_allocation * memory_mmap_alloc(size_t len, size_t alignment
|
|||
|
||||
auto *ma = new struct memory_allocation;
|
||||
if (!ma)
|
||||
return nullptr;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
if (m->flags & (int) MemoryFlags::HUGEPAGE) {
|
||||
#ifdef __linux__
|
||||
|
|
|
@ -55,7 +55,7 @@ int node_init(struct node *n, struct node_type *vt)
|
|||
n->_vt = vt;
|
||||
n->_vd = new char[vt->size];
|
||||
if (!n->_vd)
|
||||
throw RuntimeError("Failed to allocate memory");
|
||||
throw MemoryAllocationError();
|
||||
|
||||
memset(n->_vd, 0, vt->size);
|
||||
|
||||
|
|
|
@ -73,10 +73,12 @@ static int comedi_parse_direction(struct comedi *c, struct comedi_direction *d,
|
|||
}
|
||||
|
||||
d->chanlist = new unsigned int[d->chanlist_len];
|
||||
assert(d->chanlist != nullptr);
|
||||
if (!d->chanlist)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
d->chanspecs = new comedi_chanspec[d->chanlist_len];
|
||||
assert(d->chanspecs != nullptr);
|
||||
if (!d->chanspecs)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
json_array_foreach(json_chans, i, json_chan) {
|
||||
int num, range, aref;
|
||||
|
@ -238,7 +240,8 @@ static int comedi_start_in(struct node *n)
|
|||
/* Be prepared to consume one entire buffer */
|
||||
c->buf = new char[c->in.buffer_size];
|
||||
c->bufptr = c->buf;
|
||||
assert(c->bufptr != nullptr);
|
||||
if (!c->buf)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
info("Compiled for kernel read() interface");
|
||||
#else
|
||||
|
@ -328,7 +331,8 @@ static int comedi_start_out(struct node *n)
|
|||
const size_t local_buffer_size = d->sample_size * d->chanlist_len;
|
||||
d->buffer = new char[local_buffer_size];
|
||||
d->bufptr = d->buffer;
|
||||
assert(d->buffer != nullptr);
|
||||
if (!d->buffer)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
/* Initialize local buffer used for write() syscalls */
|
||||
for (unsigned channel = 0; channel < d->chanlist_len; channel++) {
|
||||
|
|
|
@ -212,15 +212,15 @@ int ethercat_prepare(struct node *n)
|
|||
|
||||
w->in.offsets = new unsigned[w->in.num_channels];
|
||||
if (!w->in.offsets)
|
||||
throw RuntimeError("Failed to allocate memory");
|
||||
throw MemoryAllocationError();
|
||||
|
||||
w->out.offsets = new unsigned[w->out.num_channels];
|
||||
if (!w->out.offsets)
|
||||
throw RuntimeError("Failed to allocate memory");
|
||||
throw MemoryAllocationError();
|
||||
|
||||
w->domain_regs = new ec_pdo_entry_reg_t[w->in.num_channels + w->out.num_channels + 1];
|
||||
if (!w->domain_regs)
|
||||
throw RuntimeError("Failed to allocate memory");
|
||||
throw MemoryAllocationError();
|
||||
|
||||
memset(w->domain_regs, 0, (w->in.num_channels + w->out.num_channels + 1) * sizeof(ec_pdo_entry_reg_t));
|
||||
|
||||
|
|
|
@ -220,6 +220,8 @@ int exec_write(struct node *n, struct sample *smps[], unsigned cnt, unsigned *re
|
|||
size_t wbytes;
|
||||
int ret;
|
||||
char *line = new char[1024];
|
||||
if (!line)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = io_sprint(&e->io, line, 1024, &wbytes, smps, cnt);
|
||||
if (ret < 0)
|
||||
|
|
|
@ -34,12 +34,15 @@
|
|||
#include <villas/plugin.h>
|
||||
#include <villas/io.h>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
static char * file_format_name(const char *format, struct timespec *ts)
|
||||
{
|
||||
struct tm tm;
|
||||
char *buf = new char[FILE_MAX_PATHLEN];
|
||||
if (!buf)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
/* Convert time */
|
||||
gmtime_r(&ts->tv_sec, &tm);
|
||||
|
|
|
@ -295,7 +295,7 @@ struct iec61850_receiver * iec61850_receiver_create(enum iec61850_receiver::Type
|
|||
if (!r) {
|
||||
r = new struct iec61850_receiver;
|
||||
if (!r)
|
||||
return nullptr;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
r->interface = strdup(intf);
|
||||
r->type = t;
|
||||
|
|
|
@ -656,6 +656,9 @@ int ib_start(struct node *n)
|
|||
/* Allocate space for 40 Byte GHR. We don't use this. */
|
||||
if (ib->conn.port_space == RDMA_PS_UDP) {
|
||||
ib->conn.ud.grh_ptr = new char[GRH_SIZE];
|
||||
if (!ib->conn.ud.grh_ptr)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ib->conn.ud.grh_mr = ibv_reg_mr(ib->ctx.pd, ib->conn.ud.grh_ptr, GRH_SIZE, IBV_ACCESS_LOCAL_WRITE);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,12 @@
|
|||
|
||||
#include <villas/nodes/ngsi.hpp>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/timing.h>
|
||||
#include <villas/plugin.h>
|
||||
#include <villas/node/config.h>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
/* Some global settings */
|
||||
|
@ -218,6 +220,8 @@ static int ngsi_parse_mapping(struct vlist *mapping, json_t *cfg)
|
|||
return -2;
|
||||
|
||||
auto *a = new struct ngsi_attribute;
|
||||
if (!a)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
a->index = j;
|
||||
|
||||
|
|
|
@ -83,6 +83,9 @@ int opal_type_start(villas::node::SuperNode *sn)
|
|||
send_ids = new int[send_icons];
|
||||
recv_ids = new int[recv_icons];
|
||||
|
||||
if (!send_ids || !recv_ids)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
err = OpalGetAsyncSendIDList(send_ids, send_icons * sizeof(int));
|
||||
if (err != EOK)
|
||||
error("Failed to get list of send ids (%d)", err);
|
||||
|
@ -128,6 +131,9 @@ int opal_print_global()
|
|||
auto *sbuf = new char[send_icons * 5];
|
||||
auto *rbuf = new char[recv_icons * 5];
|
||||
|
||||
if (!sbuf || !rbuf)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
for (int i = 0; i < send_icons; i++)
|
||||
strcatf(&sbuf, "%u ", send_ids[i]);
|
||||
for (int i = 0; i < recv_icons; i++)
|
||||
|
|
|
@ -359,6 +359,9 @@ int rtp_start(struct node *n)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!r->aimd.rate_hook)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
r->aimd.rate_hook->init();
|
||||
|
||||
vlist_push(&n->out.hooks, (void *) r->aimd.rate_hook);
|
||||
|
@ -396,6 +399,8 @@ int rtp_start(struct node *n)
|
|||
strftime(fn, sizeof(fn), r->aimd.log_filename, &tm);
|
||||
|
||||
r->aimd.log = new std::ofstream(fn, std::ios::out | std::ios::trunc);
|
||||
if (!r->aimd.log)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
*(r->aimd.log) << "# cnt\tfrac_loss\trate" << std::endl;
|
||||
}
|
||||
|
|
|
@ -30,12 +30,14 @@
|
|||
|
||||
#include <villas/kernel/kernel.hpp>
|
||||
#include <villas/log.h>
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/shmem.h>
|
||||
#include <villas/nodes/shmem.hpp>
|
||||
#include <villas/plugin.h>
|
||||
#include <villas/timing.h>
|
||||
#include <villas/utils.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
int shmem_parse(struct node *n, json_t *cfg)
|
||||
|
@ -81,6 +83,8 @@ int shmem_parse(struct node *n, json_t *cfg)
|
|||
error("Setting 'exec' of node %s must be an array of strings", node_name(n));
|
||||
|
||||
shm->exec = new char*[json_array_size(json_exec) + 1];
|
||||
if (!shm->exec)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
size_t i;
|
||||
json_t *json_val;
|
||||
|
|
|
@ -26,8 +26,10 @@
|
|||
|
||||
#include <villas/node.h>
|
||||
#include <villas/plugin.h>
|
||||
#include <villas/exceptions.hpp>
|
||||
#include <villas/nodes/signal_generator.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
static enum signal_generator::SignalType signal_generator_lookup_type(const char *type)
|
||||
|
@ -151,6 +153,8 @@ int signal_generator_start(struct node *n)
|
|||
s->counter = 0;
|
||||
s->started = time_now();
|
||||
s->last = new double[s->values];
|
||||
if (!s->last)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
for (unsigned i = 0; i < s->values; i++)
|
||||
s->last[i] = s->offset;
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
/* Forward declartions */
|
||||
static struct plugin p;
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::node;
|
||||
using namespace villas::utils;
|
||||
|
||||
|
@ -276,13 +277,12 @@ int socket_start(struct node *n)
|
|||
s->out.buflen = SOCKET_INITIAL_BUFFER_LEN;
|
||||
s->out.buf = new char[s->out.buflen];
|
||||
if (!s->out.buf)
|
||||
return -1;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
s->in.buflen = SOCKET_INITIAL_BUFFER_LEN;
|
||||
s->in.buf = new char[s->in.buflen];
|
||||
if (!s->in.buf)
|
||||
return -1;
|
||||
|
||||
throw MemoryAllocationError();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -408,6 +408,8 @@ retry: ret = io_sprint(&s->io, s->out.buf, s->out.buflen, &wbytes, smps, cnt);
|
|||
|
||||
delete[] s->out.buf;
|
||||
s->out.buf = new char[s->out.buflen];
|
||||
if (!s->out.buf)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
goto retry;
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ int stats_node_parse(struct node *n, json_t *cfg)
|
|||
|
||||
stats_sig = new struct stats_node_signal;
|
||||
if (!stats_sig)
|
||||
return -1;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = stats_node_signal_parse(stats_sig, json_signal);
|
||||
if (ret)
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <villas/plugin.h>
|
||||
#include <villas/nodes/test_rtt.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
static struct plugin p;
|
||||
|
@ -103,6 +104,8 @@ int test_rtt_prepare(struct node *n)
|
|||
max_values = c->values;
|
||||
|
||||
c->filename_formatted = new char[NAME_MAX];
|
||||
if (!c->filename_formatted)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
strftime(c->filename_formatted, NAME_MAX, c->filename, &tm);
|
||||
}
|
||||
|
@ -220,6 +223,8 @@ int test_rtt_parse(struct node *n, json_t *cfg)
|
|||
for (int i = 0; i < numrates; i++) {
|
||||
for (int j = 0; j < numvalues; j++) {
|
||||
auto *c = new struct test_rtt_case;
|
||||
if (!c)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
c->rate = rates[i];
|
||||
c->values = values[j];
|
||||
|
|
|
@ -316,6 +316,8 @@ int uldaq_parse(struct node *n, json_t *cfg)
|
|||
|
||||
u->in.channel_count = vlist_length(&n->in.signals);
|
||||
u->in.queues = new struct AiQueueElement[u->in.channel_count];
|
||||
if (!u->in.queues)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
json_array_foreach(json_signals, i, json_signal) {
|
||||
const char *range_str = nullptr, *input_mode_str = nullptr;
|
||||
|
@ -525,10 +527,8 @@ int uldaq_start(struct node *n)
|
|||
/* Allocate a buffer to receive the data */
|
||||
u->in.buffer_len = u->in.channel_count * n->in.vectorize * 50;
|
||||
u->in.buffer = new double[u->in.buffer_len];
|
||||
if (!u->in.buffer) {
|
||||
warning("Out of memory, unable to create scan buffer");
|
||||
return -1;
|
||||
}
|
||||
if (!u->in.buffer)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = uldaq_connect(n);
|
||||
if (ret)
|
||||
|
|
|
@ -101,6 +101,9 @@ static int websocket_connection_init(struct websocket_connection *c)
|
|||
c->buffers.recv = new Buffer(DEFAULT_WEBSOCKET_BUFFER_SIZE);
|
||||
c->buffers.send = new Buffer(DEFAULT_WEBSOCKET_BUFFER_SIZE);
|
||||
|
||||
if (!c->buffers.recv || !c->buffers.send)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
c->state = websocket_connection::State::INITIALIZED;
|
||||
|
||||
return 0;
|
||||
|
@ -393,6 +396,8 @@ int websocket_start(struct node *n)
|
|||
const char *format;
|
||||
auto *d = (struct websocket_destination *) vlist_at(&w->destinations, i);
|
||||
auto *c = new struct websocket_connection;
|
||||
if (!c)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
c->state = websocket_connection::State::CONNECTING;
|
||||
|
||||
|
@ -546,6 +551,10 @@ int websocket_parse(struct node *n, json_t *cfg)
|
|||
error("The 'destinations' setting of node %s must be an array of URLs", node_name(n));
|
||||
|
||||
auto *d = new struct websocket_destination;
|
||||
if (!d)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
memset(d, 0, sizeof(struct websocket_destination));
|
||||
|
||||
d->uri = strdup(uri);
|
||||
|
||||
|
|
|
@ -276,6 +276,8 @@ int path_prepare(struct vpath *p)
|
|||
/* For other mappings we create new signal descriptors */
|
||||
else {
|
||||
sig = new struct signal;
|
||||
if (!sig)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = signal_init_from_mapping(sig, me, j);
|
||||
if (ret)
|
||||
|
@ -383,6 +385,8 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes)
|
|||
/* Create new path_source of not existing */
|
||||
if (!ps) {
|
||||
ps = new struct vpath_source;
|
||||
if (!ps)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ps->node = me->node;
|
||||
ps->masked = false;
|
||||
|
@ -407,6 +411,8 @@ int path_parse(struct vpath *p, json_t *cfg, struct vlist *nodes)
|
|||
throw ConfigError(cfg, "node-config-path", "Every node must only be used by a single path as destination");
|
||||
|
||||
auto *pd = new struct vpath_destination;
|
||||
if (!pd)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
pd->node = n;
|
||||
pd->node->output_path = p;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <villas/utils.hpp>
|
||||
#include <villas/node.h>
|
||||
#include <villas/mapping.h>
|
||||
#include <villas/exceptions.hpp>
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
@ -108,7 +109,7 @@ struct signal * signal_create(const char *name, const char *unit, enum SignalTyp
|
|||
|
||||
sig = new struct signal;
|
||||
if (!sig)
|
||||
return nullptr;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = signal_init(sig);
|
||||
if (ret)
|
||||
|
@ -160,7 +161,7 @@ struct signal * signal_copy(struct signal *s)
|
|||
|
||||
ns = new struct signal;
|
||||
if (!ns)
|
||||
return nullptr;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
signal_init(ns);
|
||||
|
||||
|
@ -256,7 +257,7 @@ int signal_list_parse(struct vlist *list, json_t *cfg)
|
|||
json_array_foreach(cfg, i, json_signal) {
|
||||
s = new struct signal;
|
||||
if (!s)
|
||||
return -1;
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = signal_init(s);
|
||||
if (ret)
|
||||
|
|
|
@ -27,17 +27,21 @@
|
|||
|
||||
#include <villas/socket_addr.h>
|
||||
#include <villas/utils.hpp>
|
||||
#include <villas/exceptions.hpp>
|
||||
|
||||
#ifdef WITH_SOCKET_LAYER_ETH
|
||||
#include <villas/kernel/nl.h>
|
||||
#endif /* WITH_SOCKET_LAYER_ETH */
|
||||
|
||||
using namespace villas;
|
||||
using namespace villas::utils;
|
||||
|
||||
char * socket_print_addr(struct sockaddr *saddr)
|
||||
{
|
||||
union sockaddr_union *sa = (union sockaddr_union *) saddr;
|
||||
char *buf = new char[64];
|
||||
if (!buf)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
/* Address */
|
||||
switch (sa->sa.sa_family) {
|
||||
|
|
|
@ -153,7 +153,7 @@ void SuperNode::parse(json_t *cfg)
|
|||
|
||||
auto *n = new struct node;
|
||||
if (!n)
|
||||
throw RuntimeError("Failed to allocate memory");
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = node_init(n, nt);
|
||||
if (ret)
|
||||
|
@ -179,6 +179,8 @@ void SuperNode::parse(json_t *cfg)
|
|||
json_t *json_path;
|
||||
json_array_foreach(json_paths, i, json_path) {
|
||||
parse: auto *p = new vpath;
|
||||
if (!p)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = path_init(p);
|
||||
if (ret)
|
||||
|
|
|
@ -197,6 +197,8 @@ check: if (optarg == endptr)
|
|||
throw RuntimeError("Vectorize option must be greater than 0");
|
||||
|
||||
smps = new struct sample*[cnt];
|
||||
if (!smps)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
ret = pool_init(&p, 10 * cnt, SAMPLE_LENGTH(DEFAULT_SAMPLE_LENGTH));
|
||||
if (ret)
|
||||
|
|
|
@ -88,7 +88,11 @@ RelaySession * RelaySession::get(lws *wsi)
|
|||
|
||||
auto it = sessions.find(sid);
|
||||
if (it == sessions.end()) {
|
||||
return new RelaySession(sid);
|
||||
auto *rs = new RelaySession(sid);
|
||||
if (!rs)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
return rs;
|
||||
}
|
||||
else {
|
||||
logger->info("Found existing session: {}", sid);
|
||||
|
|
|
@ -220,8 +220,13 @@ check: if (optarg == endptr)
|
|||
|
||||
/* Open files */
|
||||
std::vector<TestCmpSide *> sides;
|
||||
for (auto filename : filenames)
|
||||
sides.push_back(new TestCmpSide(filename, fmt, dtypes, &pool));
|
||||
for (auto filename : filenames) {
|
||||
auto *s = new TestCmpSide(filename, fmt, dtypes, &pool);
|
||||
if (!s)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
sides.push_back(s);
|
||||
}
|
||||
|
||||
line = 0;
|
||||
for (;;) {
|
||||
|
|
|
@ -174,6 +174,9 @@ check: if (optarg == endptr)
|
|||
struct sample *smp_send = (struct sample *) new char[SAMPLE_LENGTH(2)];
|
||||
struct sample *smp_recv = (struct sample *) new char[SAMPLE_LENGTH(2)];
|
||||
|
||||
if (!smp_send || !smp_recv)
|
||||
throw MemoryAllocationError();
|
||||
|
||||
struct node *node;
|
||||
|
||||
if (!uri.empty())
|
||||
|
|
|
@ -47,6 +47,7 @@ Test(mapping, parse_nodes)
|
|||
|
||||
for (unsigned i = 0; i < ARRAY_LEN(node_names); i++) {
|
||||
struct node *n = new struct node;
|
||||
cr_assert_not_null(n);
|
||||
|
||||
n->name = strdup(node_names[i]);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue