Fix read after free bug when writing to pcap files