From: Mathieu Desnoyers Date: Fri, 21 Feb 2014 18:13:14 +0000 (-0500) Subject: Fix: tracepoint out of memory handling X-Git-Tag: v2.4.0~13 X-Git-Url: https://git.lttng.org/?p=lttng-ust.git;a=commitdiff_plain;h=d6297168f9042cdc550507bb5e97cee7037c34d3 Fix: tracepoint out of memory handling CID 1021247 (#1 of 1): Dereference null return value (NULL_RETURNS)3. dereference: Dereferencing a null pointer "pl". Handle more gracefully add_callsite memory allocation failure too. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/tracepoint.c b/liblttng-ust/tracepoint.c index 8c137a38..00c47196 100644 --- a/liblttng-ust/tracepoint.c +++ b/liblttng-ust/tracepoint.c @@ -380,7 +380,10 @@ static void add_callsite(struct tracepoint_lib * lib, struct tracepoint *tp) hash = jhash(name, name_len, 0); head = &callsite_table[hash & (CALLSITE_TABLE_SIZE - 1)]; e = zmalloc(sizeof(struct callsite_entry)); - assert(e); + if (!e) { + PERROR("Unable to add callsite for tracepoint \"%s\"", name); + return; + } cds_hlist_add_head(&e->hlist, head); e->tp = tp; cds_list_add(&e->node, &lib->callsites); @@ -729,7 +732,10 @@ int tracepoint_register_lib(struct tracepoint * const *tracepoints_start, init_tracepoint(); pl = (struct tracepoint_lib *) zmalloc(sizeof(struct tracepoint_lib)); - + if (!pl) { + PERROR("Unable to register tracepoint lib"); + return -1; + } pl->tracepoints_start = tracepoints_start; pl->tracepoints_count = tracepoints_count; CDS_INIT_LIST_HEAD(&pl->callsites);