From f86ddc72becf1f1c3a71b23a05e0db4ef24318da Mon Sep 17 00:00:00 2001 From: rke Date: Thu, 24 Jun 2021 12:55:38 +0200 Subject: [PATCH] memory cleanups --- pcap.c | 11 +++++++++-- pcapfix.c | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pcap.c b/pcap.c index 9d65bc7..3d198eb 100644 --- a/pcap.c +++ b/pcap.c @@ -204,6 +204,7 @@ int fix_pcap(FILE *pcap, FILE *pcap_fix) { off_t bytes; /* read/written bytes counter */ off_t filesize; /* filesize of input file in bytes */ unsigned short hdr_integ; /* integrity counter of global header */ + int res; /* return code */ /* init write buffer */ writebuffer = malloc(1024000); @@ -218,12 +219,16 @@ int fix_pcap(FILE *pcap, FILE *pcap_fix) { /* check space of pcap global header */ if (filesize < (off_t)sizeof(global_hdr)) { printf("[-] File is too small to read pcap global header.\n"); + free(writebuffer); return(-2); } printf("[*] Analyzing Global Header...\n"); bytes = fread(&global_hdr, sizeof(global_hdr), 1, pcap); /* read first bytes of input file into struct */ - if (bytes != 1) return -3; + if (bytes != 1) { + free(writebuffer); + return -3; + } /* init integrity counter */ hdr_integ = 0; @@ -345,7 +350,9 @@ int fix_pcap(FILE *pcap, FILE *pcap_fix) { /* END OF GLOBAL HEADER CHECK */ /* start checking packets now */ - return(fix_pcap_packets(pcap, pcap_fix, filesize, global_hdr, hdr_integ, writebuffer, writepos)); + res = fix_pcap_packets(pcap, pcap_fix, filesize, global_hdr, hdr_integ, writebuffer, writepos); + free(writebuffer); + return(res); } /* diff --git a/pcapfix.c b/pcapfix.c index 3efdc27..d60ea7f 100644 --- a/pcapfix.c +++ b/pcapfix.c @@ -432,6 +432,7 @@ int main(int argc, char *argv[]) { /* delete output file due to failure */ if (strcmp(filename, filename_fix) != 0) remove(filename_fix); + free(filename_fix); /* deep scan / soft mode dependent output */ if (deep_scan == 0 || soft_mode == 0) printf("If you are SURE that there are pcap packets inside, try with deep scan (-d) (pcap only!) and/or soft mode (-s) to find them!\n\n");