aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-12-18 22:58:24 -0800
committerGuy Harris <guy@alum.mit.edu>2018-12-19 06:59:09 +0000
commit05b43fc5af805dde1bdbf74dd1448690f3a10705 (patch)
tree9cd2e3c74d47a13582ffb0b35dc1eb3c42b80dba
parent5bef36f1532f640daaf0c94e1b7744ae5fdcf999 (diff)
Clean up exp_pdu_open() API.
It really shouldn't free the comment passed to it, as the caller allocated it, and knows how to free it if necessary; it might not even have been allocated. Make the comment argument a "const char *" to 1) allow passing string constants etc. and 2) to catch any attempts to free it in exp_pdu_open(). Make the callers free it after exp_pdu_open() returns. (Alternatively, we could have exp_pdu_open() take the file name argument and generate the comment itself, so that all code paths generate the same comment.) Change-Id: I6e6924b05565761b641a6c3b4d9a2e97f4264e1b Ping-Bug: 15365 Reviewed-on: https://code.wireshark.org/review/31105 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--tshark.c2
-rw-r--r--ui/export_pdu_ui_utils.c2
-rw-r--r--ui/tap_export_pdu.c3
-rw-r--r--ui/tap_export_pdu.h2
4 files changed, 4 insertions, 5 deletions
diff --git a/tshark.c b/tshark.c
index 00c28db781..e02b61b663 100644
--- a/tshark.c
+++ b/tshark.c
@@ -1977,10 +1977,10 @@ real_main(int argc, char *argv[])
/* Activate the export PDU tap */
comment = g_strdup_printf("Dump of PDUs from %s", cf_name);
err = exp_pdu_open(&exp_pdu_tap_data, exp_fd, comment);
+ g_free(comment);
if (err != 0) {
cfile_dump_open_failure_message("TShark", exp_pdu_filename, err,
WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
- g_free(comment);
exit_status = INVALID_EXPORT;
goto clean_exit;
}
diff --git a/ui/export_pdu_ui_utils.c b/ui/export_pdu_ui_utils.c
index a567a61991..c9e40b7a24 100644
--- a/ui/export_pdu_ui_utils.c
+++ b/ui/export_pdu_ui_utils.c
@@ -43,8 +43,8 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
comment = g_strdup_printf("Dump of PDUs from %s", cfile.filename);
err = exp_pdu_open(exp_pdu_tap_data, import_file_fd, comment);
+ g_free(comment);
if (err != 0) {
- g_free(comment);
cfile_dump_open_failure_alert_box(capfile_name ? capfile_name : "temporary file",
err, WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
goto end;
diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c
index 25232f0452..d3302a5aca 100644
--- a/ui/tap_export_pdu.c
+++ b/ui/tap_export_pdu.c
@@ -82,7 +82,7 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt, const
}
int
-exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
+exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, const char *comment)
{
int err;
@@ -103,7 +103,6 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
/* options */
wtap_block_add_string_option(shb_hdr, OPT_COMMENT, comment, strlen(comment));
- g_free(comment);
/*
* UTF-8 string containing the name of the operating system used to create
diff --git a/ui/tap_export_pdu.h b/ui/tap_export_pdu.h
index ea5c4077e1..9ae2dea65f 100644
--- a/ui/tap_export_pdu.h
+++ b/ui/tap_export_pdu.h
@@ -41,7 +41,7 @@ char *exp_pdu_pre_open(const char *tap_name, const char *filter,
*
* @return 0 on success or a wtap error code.
*/
-int exp_pdu_open(exp_pdu_t *data, int fd, char *comment);
+int exp_pdu_open(exp_pdu_t *data, int fd, const char *comment);
/* Stops the PDUs export. */
int exp_pdu_close(exp_pdu_t *exp_pdu_tap_data);