Changeset 16840ea


Ignore:
Timestamp:
02/19/15 17:01:12 (6 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:
e8c0a9c
Parents:
92020b8
Message:

Revert "Attempt at fixing DAG device name memory leak"

This reverts commit 4bd639385249b21fc565a990eb5d1787976d1266.

Turns out there was no memory leak this was being free()d.
I was not obvious but it was stored against the dag device
and free()d when it was.

I have also added a comment for future developers.

Conflicts:

lib/format_dag25.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_dag25.c

    r92020b8 r16840ea  
    108108/* "Global" data that is stored for each DAG output trace */
    109109struct dag_format_data_out_t {
    110         /* String containing the DAG device name */
    111         char *device_name;
    112110        /* The DAG device being used for writing */
    113111        struct dag_dev_t *device;
     
    160158        /* DAG device */
    161159        struct dag_dev_t *device;
    162         /* String containing the DAG device name */
    163         char *device_name;
    164160        /* Boolean flag indicating whether the trace is currently attached */
    165161        int stream_attached;
     
    228224        FORMAT_DATA_OUT->stream_attached = 0;
    229225        FORMAT_DATA_OUT->device = NULL;
    230         FORMAT_DATA_OUT->device_name = NULL;
    231226        FORMAT_DATA_OUT->dagstream = 0;
    232227        FORMAT_DATA_OUT->waiting = 0;
     
    254249        memset(&stream_data, 0, sizeof(stream_data));
    255250        libtrace_list_push_back(FORMAT_DATA->per_stream, &stream_data);
    256         FORMAT_DATA->device_name = NULL;
    257251}
    258252
     
    419413static int dag_init_output(libtrace_out_t *libtrace)
    420414{
     415        /* Upon successful creation, the device name is stored against the
     416         * device and free when it is free()d */
     417        char *dag_dev_name = NULL;
    421418        char *scan = NULL;
    422419        struct dag_dev_t *dag_device = NULL;
     
    441438         * If no stream is specified, we will write using stream 1 */
    442439        if ((scan = strchr(libtrace->uridata,',')) == NULL) {
    443                 FORMAT_DATA_OUT->device_name = strdup(libtrace->uridata);
     440                dag_dev_name = strdup(libtrace->uridata);
    444441        } else {
    445                 FORMAT_DATA_OUT->device_name =
    446                                 (char *)strndup(libtrace->uridata,
     442                dag_dev_name = (char *)strndup(libtrace->uridata,
    447443                                (size_t)(scan - libtrace->uridata));
    448444                stream = atoi(++scan);
     
    451447
    452448        /* See if our DAG device is already open */
    453         dag_device = dag_find_open_device(FORMAT_DATA_OUT->device_name);
     449        dag_device = dag_find_open_device(dag_dev_name);
    454450
    455451        if (dag_device == NULL) {
    456452                /* Device not yet opened - open it ourselves */
    457                 dag_device = dag_open_output_device(libtrace,
    458                                 FORMAT_DATA_OUT->device_name);
     453                dag_device = dag_open_output_device(libtrace, dag_dev_name);
     454        } else {
     455                /* Otherwise, just use the existing one */
     456                free(dag_dev_name);
     457                dag_dev_name = NULL;
    459458        }
    460459
    461460        /* Make sure we have successfully opened a DAG device */
    462461        if (dag_device == NULL) {
    463                 if (FORMAT_DATA_OUT->device_name) {
    464                         free(FORMAT_DATA_OUT->device_name);
    465                         FORMAT_DATA_OUT->device_name = NULL;
     462                if (dag_dev_name) {
     463                        free(dag_dev_name);
    466464                }
    467465                pthread_mutex_unlock(&open_dag_mutex);
     
    476474/* Creates and initialises a DAG input trace */
    477475static int dag_init_input(libtrace_t *libtrace) {
     476        /* Upon successful creation, the device name is stored against the
     477         * device and free when it is free()d */
     478        char *dag_dev_name = NULL;
    478479        char *scan = NULL;
    479480        int stream = 0;
     
    494495         */
    495496        if ((scan = strchr(libtrace->uridata,',')) == NULL) {
    496                 FORMAT_DATA->device_name = strdup(libtrace->uridata);
     497                dag_dev_name = strdup(libtrace->uridata);
    497498        } else {
    498                 FORMAT_DATA->device_name = (char *)strndup(libtrace->uridata,
     499                dag_dev_name = (char *)strndup(libtrace->uridata,
    499500                                (size_t)(scan - libtrace->uridata));
    500501                stream = atoi(++scan);
     
    504505
    505506        /* See if our DAG device is already open */
    506         dag_device = dag_find_open_device(FORMAT_DATA->device_name);
     507        dag_device = dag_find_open_device(dag_dev_name);
    507508
    508509        if (dag_device == NULL) {
    509510                /* Device not yet opened - open it ourselves */
    510                 dag_device=dag_open_device(libtrace, FORMAT_DATA->device_name);
     511                dag_device = dag_open_device(libtrace, dag_dev_name);
     512        } else {
     513                /* Otherwise, just use the existing one */
     514                free(dag_dev_name);
     515                dag_dev_name = NULL;
    511516        }
    512517
    513518        /* Make sure we have successfully opened a DAG device */
    514519        if (dag_device == NULL) {
    515                 if (FORMAT_DATA->device_name)
    516                         free(FORMAT_DATA->device_name);
    517                 FORMAT_DATA->device_name = NULL;
     520                if (dag_dev_name)
     521                        free(dag_dev_name);
     522                dag_dev_name = NULL;
    518523                pthread_mutex_unlock(&open_dag_mutex);
    519524                return -1;
     
    806811        /* Clear the list */
    807812        libtrace_list_deinit(FORMAT_DATA->per_stream);
    808 
    809         if (FORMAT_DATA->device_name)
    810                 free(FORMAT_DATA->device_name);
    811813        free(libtrace->format_data);
    812814        pthread_mutex_unlock(&open_dag_mutex);
     
    844846        if (FORMAT_DATA_OUT->device->ref_count == 0)
    845847                dag_close_device(FORMAT_DATA_OUT->device);
    846         if (FORMAT_DATA_OUT->device_name)
    847                 free(FORMAT_DATA_OUT->device_name);
    848848        free(libtrace->format_data);
    849849        pthread_mutex_unlock(&open_dag_mutex);
Note: See TracChangeset for help on using the changeset viewer.