Changeset 1935565 for lib/trace.c


Ignore:
Timestamp:
11/29/12 10:26:27 (8 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
f240823
Parents:
17dc71c
Message:
  • Fixed double free bug when using trace_event to read from a trace file. Previously, if you tried to clean up properly after finishing with trace_event, you would get a double free bug because the packet buffer was being freed twice: once during trace_destroy() (because of the internal packet stored by trace_event) and again during trace_destroy_packet().
  • Removed some of the unused code from trace_event_trace in format_helper.c
  • Make sure we only free packet->buffer during trace_destroy_packet if it is not NULL
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    re90d5a8 r1935565  
    592592        if (libtrace->uridata)
    593593                free(libtrace->uridata);
    594         if (libtrace->event.packet)
    595                 trace_destroy_packet(libtrace->event.packet);
     594        if (libtrace->event.packet) {
     595                /* Don't use trace_destroy_packet here - there is almost
     596                 * certainly going to be another libtrace_packet_t that is
     597                 * pointing to the buffer for this packet, so we don't want
     598                 * to free it. Rather, it will get freed when the user calls
     599                 * trace_destroy_packet on the libtrace_packet_t that they
     600                 * own.
     601                 *
     602                 * All we need to do then is free our packet structure itself.
     603                 */
     604                 free(libtrace->event.packet);
     605        }
    596606        free(libtrace);
    597607}
     
    664674 */
    665675DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet) {
    666         if (packet->buf_control == TRACE_CTRL_PACKET) {
     676        if (packet->buf_control == TRACE_CTRL_PACKET && packet->buffer) {
    667677                free(packet->buffer);
    668678        }
Note: See TracChangeset for help on using the changeset viewer.