Wireshark-dev: [Wireshark-dev] New packet list - small fixes

From: Jakub Zawadzki <darkjames@xxxxxxxxxxxxxxxx>
Date: Sat, 11 Jul 2009 23:56:10 +0200
Hi,

This patch fix off-by-one error in packet_list_init()
and makes new_packet_list_append() to use stack for row_data_t.

Btw. There's new issue, when I load some capture into wireshark, and don't
click any packet. I got SIGSEGV on closing capture (^W) on quiting (^Q)

(gdb) bt
#0  0x000000000044ea8f in set_menus_for_selected_packet (cf=0x79e3e0) at menus.c:2639
#1  0x000000000044a15b in main_cf_callback (event=<value optimized out>, data=0x79e3e0, user_data=<value optimized out>) at main.c:1277
#2  0x0000000000435145 in cf_callback_invoke (event=0, data=0x79e3e0) at file.c:146
#3  0x0000000000438c7e in cf_close (cf=0x79e3e0) at file.c:385
[cut]

2639        set_menu_sensitivity(packet_list_menu_factory, "/SCTP",
2640                             cf->current_frame != NULL ? (cf->edt->pi.ipproto == IP_PROTO_SCTP) : FALSE);

cf->current_frame $1 = (frame_data *) 0x16bcae0,
but       cf->edt $2 = (epan_dissect_t *) 0x0
diff --git gtk/new_packet_list.c gtk/new_packet_list.c
index cbf2f6c..fec3d12 100644
--- gtk/new_packet_list.c
+++ gtk/new_packet_list.c
@@ -85,20 +85,18 @@ guint
 new_packet_list_append(column_info cinfo, frame_data *fdata)
 {
 	gint i;
-	row_data_t *row_data;
+	row_data_t row_data;
 
-	row_data = g_new0(row_data_t, 1);
+	memset(&row_data, 0, sizeof(row_data_t));
 
 	for(i = 0; i < cfile.cinfo.num_cols; i++) {
-		row_data->col_text[cinfo.col_fmt[i]] =
+		row_data.col_text[cinfo.col_fmt[i]] =
 			se_strdup(cinfo.col_data[i]);
 	}
 
-	row_data->fdata = fdata;
+	row_data.fdata = fdata;
 
-	packet_list_append_record(packetlist, row_data);
-
-	g_free(row_data);
+	packet_list_append_record(packetlist, &row_data);
 
 	return packetlist->num_rows; /* XXX - Check that this is the right # */
 }
diff --git gtk/packet_list_store.c gtk/packet_list_store.c
index 7c8670b..92d4f12 100644
--- gtk/packet_list_store.c
+++ gtk/packet_list_store.c
@@ -202,10 +202,9 @@ packet_list_init(PacketList *packet_list)
 {
 	guint i;
 
-	for(i = 0; i <= NUM_COL_FMTS; i++) { /* XXX - Temporary? */
+	for(i = 0; i < NUM_COL_FMTS; i++) { /* XXX - Temporary? */
 		packet_list->column_types[i] = G_TYPE_STRING;
 	}
-	
 
 	packet_list->n_columns = NUM_COL_FMTS;
 	packet_list->num_rows = 0;