Changeset c99b1e5 for lib/trace.c


Ignore:
Timestamp:
07/01/14 18:26:16 (7 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, 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:
41148f2, dafe86a
Parents:
3296252
Message:

Fixes bug where memory was free()d despite having never been allocated.
This occurred when using the original (non-parallel) framework.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    r3296252 rc99b1e5  
    283283        libtrace->tracetime = 0;
    284284        libtrace->tick_interval = 0;
     285        libtrace->first_packets.first = 0;
     286        libtrace->first_packets.count = 0;
     287        libtrace->first_packets.packets = NULL;
    285288
    286289        /* Parse the URI to determine what sort of trace we are dealing with */
     
    641644
    642645        /* destroy any packet that are still around */
    643         if (libtrace->first_packets.packets) {
     646        if (libtrace->state != STATE_NEW && libtrace->first_packets.packets) {
    644647                for (i = 0; i < libtrace->perpkt_thread_count; ++i) {
    645648                        if(libtrace->first_packets.packets[i].packet) {
     
    648651                }
    649652                free(libtrace->first_packets.packets);
     653                assert(pthread_spin_destroy(&libtrace->first_packets.lock) == 0);
    650654        }
    651655
     
    661665       
    662666        /* Empty any packet memory */
    663 
    664         libtrace_packet_t * packet;
    665         while (libtrace_ringbuffer_try_read(&libtrace->packet_freelist,(void **) &packet))
    666                 trace_destroy_packet(packet);
    667        
    668         libtrace_ringbuffer_destroy(&libtrace->packet_freelist);
    669        
    670         for (i = 0; i < libtrace->perpkt_thread_count; ++i) {
    671                 assert (libtrace_vector_get_size(&libtrace->perpkt_threads[i].vector) == 0);
    672                 libtrace_vector_destroy(&libtrace->perpkt_threads[i].vector);
    673         }
    674         free(libtrace->perpkt_threads);
    675         libtrace->perpkt_threads = NULL;
    676         libtrace->perpkt_thread_count = 0;
     667        if (libtrace->state != STATE_NEW) {
     668                libtrace_packet_t * packet;
     669                while (libtrace_ringbuffer_try_read(&libtrace->packet_freelist,(void **) &packet))
     670                        trace_destroy_packet(packet);
     671               
     672                libtrace_ringbuffer_destroy(&libtrace->packet_freelist);
     673               
     674                for (i = 0; i < libtrace->perpkt_thread_count; ++i) {
     675                        assert (libtrace_vector_get_size(&libtrace->perpkt_threads[i].vector) == 0);
     676                        libtrace_vector_destroy(&libtrace->perpkt_threads[i].vector);
     677                }
     678                free(libtrace->perpkt_threads);
     679                libtrace->perpkt_threads = NULL;
     680                libtrace->perpkt_thread_count = 0;
     681        }
    677682       
    678683        if (libtrace->event.packet) {
Note: See TracChangeset for help on using the changeset viewer.