aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonnie Sahlberg <ronnie_sahlberg@ozemail.com.au>2005-09-01 09:03:29 +0000
committerRonnie Sahlberg <ronnie_sahlberg@ozemail.com.au>2005-09-01 09:03:29 +0000
commit55add7077f67b75200f70119875f27f086775880 (patch)
tree40523152f48c92d78b90981383f86216eba55ecd
parent494c071cfb448597ab2967ef81c12fe9383d5ff8 (diff)
convert one sprintf into g_snprintf()
at the same time, make proto_construct_dfilter_string() return an emem allocated string. This fixes a tiny memleak in print.c that never freed the string returned by this function. svn path=/trunk/; revision=15651
-rw-r--r--epan/proto.c21
-rw-r--r--gtk/main.c6
-rw-r--r--tap-protocolinfo.c1
3 files changed, 15 insertions, 13 deletions
diff --git a/epan/proto.c b/epan/proto.c
index cba96405ad..537decc984 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -41,6 +41,7 @@
#include "epan_dissect.h"
#include "slab.h"
#include "tvbuff.h"
+#include "emem.h"
#define cVALS(x) (const value_string*)(x)
@@ -4370,6 +4371,10 @@ proto_can_match_selected(field_info *finfo, epan_dissect_t *edt)
}
}
+/* This function returns a string allocated with packet lifetime scope.
+ * You do not need to [g_]free() this string since it willb e automatically
+ * freed once the next packet is dissected.
+ */
char*
proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
{
@@ -4436,7 +4441,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
* 1 byte for the trailing '\0'.
*/
dfilter_len = abbrev_len + 4 + 11 + 1;
- buf = g_malloc0(dfilter_len);
+ buf = ep_alloc0(dfilter_len);
format = hfinfo_numeric_format(hfinfo);
g_snprintf(buf, dfilter_len, format, hfinfo->abbrev, fvalue_get_integer(&finfo->value));
break;
@@ -4460,7 +4465,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
* 1 byte for the trailing '\0'.
*/
dfilter_len = abbrev_len + 4 + 22 + 1;
- buf = g_malloc0(dfilter_len);
+ buf = ep_alloc0(dfilter_len);
format = hfinfo_numeric_format(hfinfo);
g_snprintf(buf, dfilter_len, format, hfinfo->abbrev, fvalue_get_integer64(&finfo->value));
break;
@@ -4473,7 +4478,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
* 1 byte for the trailing '\0'.
*/
dfilter_len = abbrev_len + 4 + 2 + 8 + 1;
- buf = g_malloc0(dfilter_len);
+ buf = ep_alloc0(dfilter_len);
g_snprintf(buf, dfilter_len, "%s == 0x%08x", hfinfo->abbrev,
fvalue_get_integer(&finfo->value));
break;
@@ -4486,7 +4491,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
*/
stringified = ip6_to_str((struct e_in6_addr*) fvalue_get(&finfo->value));
dfilter_len = abbrev_len + 4 + strlen(stringified) + 1;
- buf = g_malloc0(dfilter_len);
+ buf = ep_alloc0(dfilter_len);
g_snprintf(buf, dfilter_len, "%s == %s", hfinfo->abbrev,
stringified);
break;
@@ -4511,7 +4516,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
dfilter_len = fvalue_string_repr_len(&finfo->value,
FTREPR_DFILTER);
dfilter_len += abbrev_len + 4 + 1;
- buf = g_malloc0(dfilter_len);
+ buf = ep_alloc0(dfilter_len);
/* Create the string */
g_snprintf(buf, dfilter_len, "%s == ", hfinfo->abbrev);
@@ -4521,7 +4526,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
break;
case FT_PROTOCOL:
- buf = g_strdup(finfo->hfinfo->abbrev);
+ buf = ep_strdup(finfo->hfinfo->abbrev);
break;
default:
@@ -4533,7 +4538,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
* If "edt" is NULL, the answer is "no".
*/
if (edt == NULL)
- return FALSE;
+ return NULL;
/*
* Is this field part of the raw frame tvbuff?
@@ -4569,7 +4574,7 @@ proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt)
return NULL;
start = finfo->start;
- buf = g_malloc0(32 + length * 3);
+ buf = ep_alloc0(32 + length * 3);
ptr = buf;
sprintf(ptr, "frame[%d:%d] == ", finfo->start, length);
diff --git a/gtk/main.c b/gtk/main.c
index 23201d2d8b..e2aa215c96 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -65,6 +65,7 @@
#include <epan/dfilter/dfilter.h>
#include <epan/strutil.h>
#include <epan/addr_resolv.h>
+#include <epan/emem.h>
/* general (not GTK specific) */
#include "file.h"
@@ -266,9 +267,6 @@ match_selected_cb_do(gpointer data, int action, gchar *text)
/* Free up the new filter text. */
g_free(new_filter);
-
- /* Free up the generated text we were handed. */
- g_free(text);
}
void
@@ -404,7 +402,7 @@ get_text_from_packet_list(gpointer data)
strlen(cfile.cinfo.col_expr_val[column]) != 0) {
len = strlen(cfile.cinfo.col_expr[column]) +
strlen(cfile.cinfo.col_expr_val[column]) + 5;
- buf = g_malloc0(len);
+ buf = ep_alloc0(len);
g_snprintf(buf, len, "%s == %s", cfile.cinfo.col_expr[column],
cfile.cinfo.col_expr_val[column]);
}
diff --git a/tap-protocolinfo.c b/tap-protocolinfo.c
index 701d0ffc14..909ac8c240 100644
--- a/tap-protocolinfo.c
+++ b/tap-protocolinfo.c
@@ -79,7 +79,6 @@ protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const vo
str=proto_construct_dfilter_string(gp->pdata[i], NULL);
if(str){
col_append_fstr(pinfo->cinfo, COL_INFO, " %s",str);
- g_free(str);
}
}
return 0;