aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorDavid Perry <boolean263@protonmail.com>2021-08-04 13:18:46 -0400
committerGuy Harris <gharris@sonic.net>2021-08-10 00:08:15 +0000
commit6e12643f198500245ee6eff999804e468481a7b3 (patch)
tree0d08844a58e4cf465b1d13ecf70a736a5e772105 /wiretap
parent4aee4059745f6089e530344289e7ea24d5ec2db4 (diff)
[#17478] free blocks in more places
Bug 17478 was caused by `wtap_rec.block` being allocated for each packet, but not freed when it was done being used -- typically at the end of a loop. Rather than requiring each caller of `wtap_read()` to know to free a member of `rec`, I added a new function `wtap_rec_reset()` for a slightly cleaner API. Added calls to it everywhere that seemed to make sense. Fixes #17478
Diffstat (limited to 'wiretap')
-rw-r--r--wiretap/merge.c1
-rw-r--r--wiretap/wtap.c11
-rw-r--r--wiretap/wtap.h4
3 files changed, 14 insertions, 2 deletions
diff --git a/wiretap/merge.c b/wiretap/merge.c
index fb9638055c..cc732d664c 100644
--- a/wiretap/merge.c
+++ b/wiretap/merge.c
@@ -945,6 +945,7 @@ merge_process_packets(wtap_dumper *pdh, const int file_type,
status = MERGE_ERR_CANT_WRITE_OUTFILE;
break;
}
+ wtap_rec_reset(rec);
}
if (cb)
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 281dd2f192..5ec3286d4f 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -1669,13 +1669,20 @@ wtap_rec_init(wtap_rec *rec)
*/
}
-/* clean up record metadata */
+/* re-initialize record */
void
-wtap_rec_cleanup(wtap_rec *rec)
+wtap_rec_reset(wtap_rec *rec)
{
wtap_block_unref(rec->block);
rec->block = NULL;
rec->block_was_modified = FALSE;
+}
+
+/* clean up record metadata */
+void
+wtap_rec_cleanup(wtap_rec *rec)
+{
+ wtap_rec_reset(rec);
ws_buffer_free(&rec->options_buf);
}
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 8759981654..d10e6856c1 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1752,6 +1752,10 @@ gboolean wtap_seek_read(wtap *wth, gint64 seek_off, wtap_rec *rec,
WS_DLL_PUBLIC
void wtap_rec_init(wtap_rec *rec);
+/*** Re-initialize a wtap_rec structure ***/
+WS_DLL_PUBLIC
+void wtap_rec_reset(wtap_rec *rec);
+
/*** clean up a wtap_rec structure, freeing what wtap_rec_init() allocated */
WS_DLL_PUBLIC
void wtap_rec_cleanup(wtap_rec *rec);