Don't allocate the interfaces array until we've read the SHB.
authorGuy Harris <guy@alum.mit.edu>
Wed, 15 Oct 2014 23:55:54 +0000 (16:55 -0700)
committerGuy Harris <guy@alum.mit.edu>
Wed, 15 Oct 2014 23:56:18 +0000 (23:56 +0000)
Nothing from the SHB gets stored in the interfaces array - it's filled
in from IDBs - so it doesn't need to exist when we read the first SHB,
and thus doesn't need to be freed if the attempt to read the SHB gets an
error or a "this isn't a pcap-ng file" indication.

Update a comment while we're at it.

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

index f997133feba67c9e8a3940365ba64bcceb4c042c..6660987a4ce29c30dfe0c7552336b2bf4bf4714b 100644 (file)
@@ -2199,8 +2199,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
     pn.if_fcslen = -1;
     pn.version_major = -1;
     pn.version_minor = -1;
-    pn.interfaces = g_array_new(FALSE, FALSE, sizeof(interface_info_t));
-
+    pn.interfaces = NULL;
 
     /* we don't expect any packet blocks yet */
     wblock.frame_buffer = NULL;
@@ -2243,9 +2242,8 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
 
     /*
      * At this point, we've decided this is a pcap-NG file, not
-     * some other type of file, so we can't return 0, as that
-     * means "this isn't a pcap-NG file, try some other file
-     * type".
+     * some other type of file, so we can't return WTAP_OPEN_NOT_MINE
+     * past this point.
      */
     wth->shb_hdr.opt_comment = wblock.data.section.opt_comment;
     wth->shb_hdr.shb_hardware = wblock.data.section.shb_hardware;
@@ -2258,6 +2256,7 @@ pcapng_open(wtap *wth, int *err, gchar **err_info)
     pcapng = (pcapng_t *)g_malloc(sizeof(pcapng_t));
     wth->priv = (void *)pcapng;
     *pcapng = pn;
+    pcapng->interfaces = g_array_new(FALSE, FALSE, sizeof(interface_info_t));
 
     wth->subtype_read = pcapng_read;
     wth->subtype_seek_read = pcapng_seek_read;