Segfault in application



NOTE: I'm posting this to gtk-list and mysql in hopes that someone on
either list can help with my problem.

I'm writing a GTK application that interfaces with a MySQL 4.0.12 DB
(only one table is InnoDB at present). At one point in my app, I force
the user to generate a customer number, my app sends an update
transaction and gets the new number from the DB. Then, the user is
allowed to insert that customer into the customers table. To make sure
the insert worked correctly, I have a select on the DB and free the
results.

The problem comes after I finish the insertCustomer call, I get a
segfault in glib with the following error:

{someaddress} g_type_init () from /usr/lib/libgobject-2.0.so.0

I'm not sure what would be causing this error "all-of-a-sudden". Here's
the relative code: In my callbacks.c file, I have the following routine
for when someone clicks the add_customer button:

void
on_add_customer_clicked                (GtkButton       *button,
                                        gpointer         user_data)
{
	/* Get a handle to all the data in the window
	   and perform the insertion into the database.
	*/
	insertCustomer(button);
	/*clearCustomer(button);*/
}

After the insertCustomer call, it comes back to this routine and sits
here for a bit before segfaulting in glib. My insertCustomer call looks
like this:

void insertCustomer( GtkButton *button )
{
	GtkWidget	*customers;
	GtkEditable	*accountEntry;
	GtkLabel	*accountLabel;
	GtkCombo	*title;
	GtkTextBuffer	*specialBuffer;
	GtkTextView		*specialView;
	GtkTextIter		*start;
	GtkTextIter		*end;
	gchar*			*specialText;
	gchar *sql;
	gint numRows;
	
	MYSQL_ROW	db_row;
	MYSQL_RES	*results;
	
	/* grab all the data from the customer entry window first.
	   A pointer to the window can be obtained through the
	   button parameter.
	*/
	
	customers = gtk_widget_get_toplevel(button);
	accountEntry = lookup_widget(customers, "cust_account_entry");
	accountLabel = lookup_widget(customers, "account_label");
	title = GTK_COMBO(lookup_widget(customers, "title_entry"));
	
	/* the GtkTextView in this window requires a bit of extra work
	   to get the text value stored in it.
	*/
	
	specialView = lookup_widget(customers, "cust_instructions");
	specialBuffer = gtk_text_view_get_buffer(specialView);
	gtk_text_buffer_get_bounds(specialBuffer, start, end);
	
	/* Contruct an SQL command from the data available in the customer
	   entry dialog. This is long, but needs to be done this way.
	*/
	
	sql = g_strconcat("insert into customers (customer_id, title, last_name, first_name, \
			company, account_code, address, suite, phone, postal_code, buzzer, zone, special) \
			values('", gtk_label_get_text(GTK_LABEL(lookup_widget(customers, "customer_number"))), "',\
			'",gtk_entry_get_text(GTK_ENTRY(title->entry)),"', \
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "last_name_entry"))),"', \
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "first_name_entry"))),"', \
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "cust_company_entry"))),"',\
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "cust_account_entry"))),"',\
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "cust_address_entry"))),"',\
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "cust_suite_entry"))),"',\
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "cust_phone_entry"))),"', \
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "cust_postal_entry"))),"', \
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "cust_buzzer_code"))),"',\
			'",gtk_entry_get_text(GTK_ENTRY(lookup_widget(customers, "cust_zone_entry"))),"',\
			'",gtk_text_buffer_get_text(specialBuffer, start, end, FALSE),"')",0L);
	
	/* connect to the DB and execute the query */
	connect_DB();
	if ( mysql_query(conx, sql) != 0 )
	{
		g_print("Insert of new customer failed\n");
		g_print("sql query is %s\n", sql);
	} else {
		g_print("Successful insert of new customer\n");
	}
	
	sql = g_strconcat("select * from customers",0L);
	if ( mysql_query(conx, "select * from customers") != 0 )
	{
		g_print("Selection of customers failed\n");
		g_print("sql query is %s\n", sql);
	} else {
		g_print("Successful selection of customers\n");
	}
	results = mysql_store_result(conx);
	db_row = mysql_fetch_row(results);
	numRows = mysql_num_rows(results);
	g_print("There are %d rows returned\n", numRows);
	mysql_free_result(results);
	/* finally close the connection to the DB */
	disconnect_DB();
	
}

It appears to work, I see the data in the Db using mysqlcc, but once the
call comes back to the on_add_customer_clicked routine in callbacks.c,
it segfaults and I just do not know why. Is there a pointer problem? a
memory problem? Any ideas?

Any help is appreciated.

-- 
 .''`.      Carl B. Constantine
: :' :     duckwing duckwing ca
`. `'    GnuPG: 135F FC30 7A02 B0EB 61DB  34E3 3AF1 DC6C 9F7A 3FF8
  `-  Debian GNU/Linux -- The power of freedom

Attachment: pgpmQecmx4OOC.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]