Changeset fd4482d


Ignore:
Timestamp:
03/09/16 09:19:43 (5 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
38c00dd, c46b7ea
Parents:
b6cbdaf
Message:

Make sure trace_create_packet() doesn't segfault

If allocating memory for the new packet fails, we now return NULL
instead of carrying on and trying to initialise the packet fields.

This has always been the intended behaviour (see some of the examples
for cases where we check if packet is NULL after calling trace_create_packet())
but I guess nobody actually implemented it...

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h.in

    rc5ac872 rfd4482d  
    14251425/** Create a new packet object
    14261426 *
    1427  * @return A pointer to an initialised libtrace_packet_t object
     1427 * @return A pointer to an initialised libtrace_packet_t object, or NULL if
     1428 * libtrace is unable to allocate space for a new packet.
    14281429 */
    14291430DLLEXPORT libtrace_packet_t *trace_create_packet(void);
  • lib/trace.c

    r7d1ada1 rfd4482d  
    638638                (libtrace_packet_t*)calloc((size_t)1,sizeof(libtrace_packet_t));
    639639
     640        if (packet == NULL)
     641                return NULL;
     642
    640643        packet->buf_control=TRACE_CTRL_PACKET;
    641644        trace_clear_cache(packet);
Note: See TracChangeset for help on using the changeset viewer.