Skip to content

Commit 990133d

Browse files
committed
Fix various bugs observed when converting from etsifile to pcapfile
* fix bad trace type in etsifile format definition * fix memory leak when demoting a packet during pcapfile format conversion * fix bad setting of packet->error when reading a packet using etsifile format
1 parent 500af71 commit 990133d

5 files changed

Lines changed: 19 additions & 6 deletions

File tree

lib/format_etsifile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int etsifile_prepare_received(libtrace_t *libtrace,
124124
wandder_attach_etsili_buffer(INPUT->decoder, packet->buffer, length, false);
125125
packet->cached.wire_length = wandder_etsili_get_pdu_length(INPUT->decoder);
126126
packet->cached.capture_length = packet->cached.wire_length;
127-
packet->error = packet->cached.capture_length;
127+
packet->error = 0;
128128
packet->fmtdata = NULL;
129129

130130
tv = wandder_etsili_get_header_timestamp(INPUT->decoder);
@@ -383,7 +383,7 @@ static void etsifile_help(void)
383383
static struct libtrace_format_t etsifile = {
384384
"etsifile",
385385
"$Id$",
386-
TRACE_FORMAT_ETSILIVE,
386+
TRACE_FORMAT_ETSIFILE,
387387
NULL, /* probe filename */
388388
NULL, /* probe magic */
389389
etsifile_init_input, /* init_input */

lib/libtrace_int.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ static inline int posix_memalign(void **memptr, size_t alignment, size_t size)
184184

185185
#define MAX_THREADS 128
186186

187+
extern int libtrace_parallel;
188+
187189
/** Data about the most recent event from a trace file */
188190
struct libtrace_event_status_t {
189191
/** A libtrace packet to store the packet when a PACKET event occurs */

lib/linktypes.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,9 @@ static void replacement_pcap_header(libtrace_packet_t *packet, char *payload,
432432

433433
char *tmp;
434434

435-
tmp = (char *)malloc(trace_get_capture_length(packet) +
436-
sizeof(libtrace_pcapfile_pkt_hdr_t));
435+
//tmp = (char *)malloc(trace_get_capture_length(packet) +
436+
// sizeof(libtrace_pcapfile_pkt_hdr_t));
437+
tmp = (char *)malloc(LIBTRACE_PACKET_BUFSIZE);
437438

438439
((libtrace_pcapfile_pkt_hdr_t *)tmp)->ts_sec = tv->tv_sec;
439440
((libtrace_pcapfile_pkt_hdr_t *)tmp)->ts_usec = tv->tv_usec;
@@ -455,6 +456,14 @@ static void replacement_pcap_header(libtrace_packet_t *packet, char *payload,
455456

456457
/* Invalidate caches */
457458
trace_clear_cache(packet);
459+
460+
/* This packet is about to gain a new "parent" trace, so make sure the old
461+
* trace doesn't keep a reference to it
462+
*/
463+
if (!libtrace_parallel && packet->trace &&
464+
packet->trace->last_packet == packet) {
465+
packet->trace->last_packet = NULL;
466+
}
458467
}
459468

460469
/* Try and remove any extraneous encapsulation that may have been added to

lib/trace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,10 @@ DLLEXPORT int trace_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet)
11641164
continue;
11651165
}
11661166
if (ret == (size_t)-1 || ret == 0) {
1167+
/* shouldn't need to do this, but just to be safe... */
1168+
if (!libtrace_parallel && libtrace->last_packet == packet) {
1169+
libtrace->last_packet = NULL;
1170+
}
11671171
packet->trace = NULL;
11681172
return ret;
11691173
}

lib/trace_parallel.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@
9191
static inline int delay_tracetime(libtrace_t *libtrace,
9292
libtrace_packet_t *packet,
9393
libtrace_thread_t *t);
94-
extern int libtrace_parallel;
95-
9694
struct mem_stats {
9795
struct memfail {
9896
uint64_t cache_hit;

0 commit comments

Comments
 (0)