Changeset e375e0f for lib


Ignore:
Timestamp:
02/28/18 15:11:24 (3 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
cachetimestamps, develop, etsilive, master, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance
Children:
e4eaca5
Parents:
5c07bfe
Message:

Fix bug where libtrace-created hasher_data was leaked.

If trace_set_hasher was called with a null hasher, libtrace
would malloc memory for storing hasher_data. However, that
memory was never freed, since we had no way of telling whether
that memory had been externally allocated and passed in to
trace_set_hasher or if the memory had been allocated by libtrace.

Added a flag to the libtrace_t structure that records who owns
hasher_data and will now free it during trace_destroy if the
memory was allocated by libtrace.

Location:
lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace_int.h

    rc7e547e re375e0f  
    182182        THREAD_PAUSED,
    183183        THREAD_STATE_MAX
     184};
     185
     186enum hash_owner {
     187        HASH_OWNED_LIBTRACE,
     188        HASH_OWNED_EXTERNAL,
    184189};
    185190
     
    347352        fn_hasher hasher;
    348353        void *hasher_data;
     354        enum hash_owner hasher_owner;
    349355        /** The pread_packet choosen path for the configuration */
    350356        int (*pread)(libtrace_t *, libtrace_thread_t *, libtrace_packet_t **, size_t);
  • lib/trace.c

    r9375d2e re375e0f  
    271271        libtrace->hasher = NULL;
    272272        libtrace->hasher_data = NULL;
     273        libtrace->hasher_owner = HASH_OWNED_EXTERNAL;
    273274        libtrace_zero_ocache(&libtrace->packet_freelist);
    274275        libtrace_zero_thread(&libtrace->hasher_thread);
     
    738739        }
    739740
     741        if (libtrace->hasher_owner == HASH_OWNED_LIBTRACE) {
     742                if (libtrace->hasher_data) {
     743                        free(libtrace->hasher_data);
     744                }
     745        }
     746
     747
    740748        if (libtrace->perpkt_cbs)
    741749                trace_destroy_callback_set(libtrace->perpkt_cbs);
  • lib/trace_parallel.c

    r5c07bfe re375e0f  
    21602160        trace->hasher_type = type;
    21612161        if (hasher) {
     2162                if (trace->hasher_owner == HASH_OWNED_LIBTRACE) {
     2163                        if (trace->hasher_data) {
     2164                                free(trace->hasher_data);
     2165                        }
     2166                }
    21622167                trace->hasher = hasher;
    21632168                trace->hasher_data = data;
     2169                trace->hasher_owner = HASH_OWNED_EXTERNAL;
    21642170        } else {
    21652171                trace->hasher = NULL;
    21662172                trace->hasher_data = NULL;
     2173                trace->hasher_owner = HASH_OWNED_LIBTRACE;
    21672174        }
    21682175
Note: See TracChangeset for help on using the changeset viewer.