From c64a9bbde75ec9c098b6028d020266e1ea023d29 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 16 Jul 2021 15:59:58 -0700 Subject: erf: make a copy of the first SHB comment. We free it, but what wtap_block_get_nth_string_option_value() returns is what's stored in the block, and it might get freed up out from under us. Save a copy of it, so that when we free it, we're not double-freeing. --- wiretap/erf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'wiretap/erf.c') diff --git a/wiretap/erf.c b/wiretap/erf.c index 9493b05818..d04bda82fb 100644 --- a/wiretap/erf.c +++ b/wiretap/erf.c @@ -2045,6 +2045,7 @@ static int erf_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) erf_dump_t *dump_priv; gchar *s; guint64 host_id; + char *first_shb_comment; dump_priv = erf_dump_priv_create(); @@ -2052,8 +2053,10 @@ static int erf_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) wdh->priv = dump_priv; wdh->subtype_finish = erf_dump_finish; - /* Get the capture comment string */ - get_user_comment_string(wdh, &dump_priv->user_comment_ptr); + /* Get the first capture comment string */ + get_user_comment_string(wdh, &first_shb_comment); + /* Save a copy of it */ + dump_priv->user_comment_ptr = g_strdup(first_shb_comment); /* XXX: If we have a capture comment or a non-ERF file assume we need to * write metadata unless we see existing metadata in the first second. */ if (dump_priv->user_comment_ptr || wdh->encap != WTAP_ENCAP_ERF) -- cgit v1.2.3