aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-03-18 17:27:57 -0700
committerGuy Harris <guy@alum.mit.edu>2015-03-19 00:28:40 +0000
commit1fdfee69d6a96b66719d34651dfa4bdc852a23ae (patch)
tree3d7967979f9db4adba2340149517fa82b39222db
parentab45f1d29006d65e713f8e0bb5dc08667a9e8b80 (diff)
Patch some memory leaks.
capture_dev_user_descr_find() and capture_dev_user_cfilter_find() return g_malloc()ated strings; we don't need to g_strdup() them to get a g_malloc()ated string, and we *do* need to free them if we aren't going to use them any more. Document that while we're at it, and give more details for the functions returning integer user-specified interface parameters as well. Change-Id: Icf98a48992b1c4168ead54bdc4cc2847da89d665 Reviewed-on: https://code.wireshark.org/review/7745 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--ui/capture_ui_utils.c88
-rw-r--r--ui/capture_ui_utils.h27
-rw-r--r--ui/qt/capture_interfaces_dialog.cpp2
-rw-r--r--ui/qt/manage_interfaces_dialog.cpp1
4 files changed, 73 insertions, 45 deletions
diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c
index 4bac875056..50317f1431 100644
--- a/ui/capture_ui_utils.c
+++ b/ui/capture_ui_utils.c
@@ -276,52 +276,52 @@ get_interface_descriptive_name(const char *if_name)
/* Do we have a user-supplied description? */
descr = capture_dev_user_descr_find(if_name);
- if (descr != NULL) {
- /* Yes - make a copy of that. */
- descr = g_strdup(descr);
- } else if (strcmp(if_name, "-") == 0) {
- /*
- * Strictly speaking, -X (extension) options are for modules, e.g. Lua
- * and using one here stretches that definition. However, this doesn't
- * waste a single-letter option on something that might be rarely used
- * and is backward-compatible to 1.0.
- */
- descr = g_strdup(ex_opt_get_nth("stdin_descr", 0));
- if (!descr) {
- descr = g_strdup("Standard input");
- }
- } else {
- /* No, we don't have a user-supplied description; did we get
- one from the OS or libpcap? */
- descr = NULL;
- if_list = capture_interface_list(&err, NULL, NULL);
- if (if_list != NULL) {
- if_entry = if_list;
- do {
- if_info = (if_info_t *)if_entry->data;
- if (strcmp(if_info->name, if_name) == 0) {
- if (if_info->friendly_name != NULL) {
- /* We have a "friendly name"; return a copy of that
- as the description - when we free the interface
- list, that'll also free up the strings to which
- it refers. */
- descr = g_strdup(if_info->friendly_name);
- } else if (if_info->vendor_description != NULL) {
- /* We have no "friendly name", but we have a vendor
- description; return a copy of that - when we free
- the interface list, that'll also free up the strings
- to which it refers. */
- descr = g_strdup(if_info->vendor_description);
+ if (descr == NULL) {
+ /* No; try to construct a descriptive name. */
+ if (strcmp(if_name, "-") == 0) {
+ /*
+ * Strictly speaking, -X (extension) options are for modules, e.g. Lua
+ * and using one here stretches that definition. However, this doesn't
+ * waste a single-letter option on something that might be rarely used
+ * and is backward-compatible to 1.0.
+ */
+ descr = g_strdup(ex_opt_get_nth("stdin_descr", 0));
+ if (!descr) {
+ descr = g_strdup("Standard input");
+ }
+ } else {
+ /* No, we don't have a user-supplied description; did we get
+ one from the OS or libpcap? */
+ descr = NULL;
+ if_list = capture_interface_list(&err, NULL, NULL);
+ if (if_list != NULL) {
+ if_entry = if_list;
+ do {
+ if_info = (if_info_t *)if_entry->data;
+ if (strcmp(if_info->name, if_name) == 0) {
+ if (if_info->friendly_name != NULL) {
+ /* We have a "friendly name"; return a copy of that
+ as the description - when we free the interface
+ list, that'll also free up the strings to which
+ it refers. */
+ descr = g_strdup(if_info->friendly_name);
+ } else if (if_info->vendor_description != NULL) {
+ /* We have no "friendly name", but we have a vendor
+ description; return a copy of that - when we free
+ the interface list, that'll also free up the strings
+ to which it refers. */
+ descr = g_strdup(if_info->vendor_description);
+ }
+ break;
}
- break;
- }
- } while ((if_entry = g_list_next(if_entry)) != NULL);
- }
- free_interface_list(if_list);
+ } while ((if_entry = g_list_next(if_entry)) != NULL);
+ }
+ free_interface_list(if_list);
- if (descr == NULL) {
- /* The interface name is all we have, so just return a copy of that. */
- descr = g_strdup(if_name);
+ if (descr == NULL) {
+ /* The interface name is all we have, so just return a copy of that. */
+ descr = g_strdup(if_name);
+ }
}
}
diff --git a/ui/capture_ui_utils.h b/ui/capture_ui_utils.h
index 28c117f02a..6b5361f83e 100644
--- a/ui/capture_ui_utils.h
+++ b/ui/capture_ui_utils.h
@@ -36,12 +36,21 @@ extern "C" {
/**
* Find user-specified capture device description that matches interface
* name, if any.
+ *
+ * @param if_name The name of the interface.
+ *
+ * @return The device description (must be g_free'd later) or NULL
+ * if not found.
*/
char *capture_dev_user_descr_find(const gchar *if_name);
/**
* Find user-specified link-layer header type that matches interface
* name, if any.
+ *
+ * @param if_name The name of the interface.
+ *
+ * @return The link-layer header type (a DLT_) or -1 if not found.
*/
gint capture_dev_user_linktype_find(const gchar *if_name);
@@ -49,6 +58,10 @@ gint capture_dev_user_linktype_find(const gchar *if_name);
/**
* Find user-specified buffer size that matches interface
* name, if any.
+ *
+ * @param if_name The name of the interface.
+ *
+ * @return The buffer size or -1 if not found.
*/
gint capture_dev_user_buffersize_find(const gchar *if_name);
#endif
@@ -56,6 +69,16 @@ gint capture_dev_user_buffersize_find(const gchar *if_name);
/**
* Find user-specified snap length that matches interface
* name, if any.
+ *
+ * @param if_name The name of the interface.
+ * @param hassnap Pointer to a variable to be set to TRUE if the
+ * interface should be given a snap length or FALSE if it shouldn't
+ * be given a snap length.
+ * @param snaplen Pointer to a variable to be set to the snap length
+ * if the interface should be given a snap length or the maximum
+ * snap length if it shouldn't be given a snap length.
+ *
+ * @return TRUE if found or FALSE if not found.
*/
gboolean capture_dev_user_snaplen_find(const gchar *if_name, gboolean *hassnap, int *snaplen);
@@ -68,6 +91,10 @@ gboolean capture_dev_user_pmode_find(const gchar *if_name);
/**
* Find user-specified capture filter that matches interface
* name, if any.
+ *
+ * @param if_name The name of the interface.
+ *
+ * @return The capture filter (must be g_free'd later) or NULL if not found.
*/
gchar* capture_dev_user_cfilter_find(const gchar *if_name);
diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp
index 89aceee1e3..f1c8539429 100644
--- a/ui/qt/capture_interfaces_dialog.cpp
+++ b/ui/qt/capture_interfaces_dialog.cpp
@@ -537,7 +537,7 @@ void CaptureInterfacesDialog::updateInterfaces()
#endif
gchar* prefFilter = capture_dev_user_cfilter_find(device->name);
if (prefFilter) {
- device->cfilter = g_strdup(prefFilter);
+ device->cfilter = prefFilter;
}
ti->setText(col_filter_, device->cfilter);
diff --git a/ui/qt/manage_interfaces_dialog.cpp b/ui/qt/manage_interfaces_dialog.cpp
index 93164c5fa8..4b36fa1256 100644
--- a/ui/qt/manage_interfaces_dialog.cpp
+++ b/ui/qt/manage_interfaces_dialog.cpp
@@ -334,6 +334,7 @@ void ManageInterfacesDialog::showLocalInterfaces()
comment = capture_dev_user_descr_find(device.name);
if (comment) {
item->setText(col_l_comment_, comment);
+ g_free(comment);
}
} else {
continue;