Changeset 1935565 for lib


Ignore:
Timestamp:
11/29/12 10:26:27 (9 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
Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/format_helper.c

    r91ea76c r1935565  
    216216        }
    217217
    218         /* This is the first packet, so just fire away. */
    219         /* TODO: finalise packet */
    220        
    221         /* XXX: Could we do this more efficiently? */
    222 
    223         /* We do a lot of freeing and creating of packet buffers with this
    224          * method, but at least it works unlike what was here previously */
    225         //if (packet->buf_control == TRACE_CTRL_PACKET) {
    226         //      free(packet->buffer);
    227         //}
    228        
    229218        /* The packet that we had read earlier is now ready to be returned
    230219         * to the user - switch all the pointers etc. over */   
     
    236225        packet->buffer = trace->event.packet->buffer;
    237226        packet->buf_control = trace->event.packet->buf_control;
    238 
    239         //trace->event.packet->buffer = NULL;
    240         //trace->event.packet->buf_control = TRACE_CTRL_EXTERNAL;
    241        
    242         //trace_destroy_packet(trace->event.packet);
    243         //trace->event.packet = NULL;
    244227
    245228        event.type = TRACE_EVENT_PACKET;
  • 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.