Fix allocation of option bocks in pcapng_read().
authorGuy Harris <guy@alum.mit.edu>
Thu, 25 Feb 2016 02:03:50 +0000 (18:03 -0800)
committerGuy Harris <guy@alum.mit.edu>
Thu, 25 Feb 2016 02:04:17 +0000 (02:04 +0000)
We don't need to allocate an WTAP_OPTION_BLOCK_IF_DESCR option block;
don't use the value we allocated.

We must not allocate an WTAP_OPTION_BLOCK_IF_STATS option block until we
need it, as we may have to allocate *more than one* of them here!  The
old code would reuse the same block, adding it more than once, causing a
"freeing already freed data"/"freeing non-allocated data" error on some
platforms.

Change-Id: I8582627c1f5deecfd4f6490dcdf8c31ee3809d12
Reviewed-on: https://code.wireshark.org/review/14130
Reviewed-by: Guy Harris <guy@alum.mit.edu>
wiretap/pcapng.c

index 879f349de460e62b01701212cc21f432f09075d4..f9042d3d7e16abb42e8d0f901d865ca8f9e04fb6 100644 (file)
@@ -2560,8 +2560,8 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
 {
     pcapng_t *pcapng = (pcapng_t *)wth->priv;
     wtapng_block_t wblock;
-    wtap_optionblock_t wtapng_if_descr = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR);
-    wtap_optionblock_t if_stats = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_STATS);
+    wtap_optionblock_t wtapng_if_descr;
+    wtap_optionblock_t if_stats;
     wtapng_if_stats_mandatory_t *if_stats_mand_block, *if_stats_mand;
     wtapng_if_descr_mandatory_t *wtapng_if_descr_mand;
 
@@ -2626,6 +2626,7 @@ pcapng_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
                         wtapng_if_descr_mand->interface_statistics = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t));
                     }
 
+                    if_stats = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_STATS);
                     if_stats_mand = (wtapng_if_stats_mandatory_t*)wtap_optionblock_get_mandatory_data(if_stats);
                     if_stats_mand->interface_id  = if_stats_mand_block->interface_id;
                     if_stats_mand->ts_high       = if_stats_mand_block->ts_high;