g_malloc never returns

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

 



Hi,

I'm currently stuck in development of a threaded glib/gobject based app on Redhat Linux 9 with glib 2.2.1.

The app receives XML messages over tcp. When G_IO_IN is signaled on the underlying g_io_channel I call a function to split and push the received message to a GQueue.

For some reason a call to g_strsplit, more exactly the g_malloc call, never returns.

Please accept my apologies for the long post.

Here are some code excerpts:

/* this func is used for handling incoming data of a channel */
gboolean conn_input_event_func (GIOChannel *iochannel, GIOCondition condition, gpointer data)
{
TMDPTCPConnection *tcpconn;
gsize bytes_read;
GIOStatus status;
GError *error = NULL;
TMDPConfig *tmdpconfig;


g_return_val_if_fail (condition == G_IO_IN, FALSE);
g_return_val_if_fail (data != NULL, FALSE); /* we need our connection here */


  tcpconn = (TMDPTCPConnection*)data;
  g_static_mutex_lock (&tcpconn->access_mutex);
  tmdpconfig = tmdp_tcp_connection_get_config (tcpconn);

if (tcpconn->connsock == NULL)
{
g_fprintf (stderr, "tmdp-tcp-connection::conn_input_event_func: tcpconn->connsock == NULL!\n");
g_static_mutex_unlock (&tcpconn->access_mutex);
return TRUE;
}


g_static_mutex_lock (&tmdpconfig->access_mutex);
status = g_io_channel_read_chars (iochannel, tmdpconfig->inbuffer, TMDP_BUFFER_SIZE-1,
&bytes_read, &error);
tmdpconfig->inbuffer[bytes_read] = '\0'; /* add a nul char to the end of the buffer */
g_static_mutex_unlock (&tmdpconfig->access_mutex);
g_static_mutex_unlock (&tcpconn->access_mutex);


  if (status == G_IO_STATUS_EOF)
   {
    /* TODO LOG */
    g_object_unref (G_OBJECT (tcpconn));

    return TRUE;
   }

if (status != G_IO_STATUS_NORMAL)
{
if (error)
{
g_fprintf (stderr, "tmdp-tcp-connection::conn_input_event_func: g_io_channel_read_chars () returned error: %s\n",
error->message); /* TODO LOG */
g_clear_error (&error);
}
else
{
g_fprintf (stderr, "tmdp-tcp-connection::conn_input_event_func: g_io_channel_read_chars () failed\n");
}
/* TODO LOG */
g_object_unref (G_OBJECT (tcpconn));


    return TRUE;
   }

g_static_mutex_lock (&tmdpconfig->access_mutex);

/* split push the received data into the out queue */
if (!split_and_push_messages (tcpconn->listener, tmdpconfig->inbuffer, &error))
{
/* TODO LOG */
g_fprintf (stderr, "tmdp-tcp-connection::conn_input_event_func: split_and_push_messages "
"returned %s\n", error->message);
}


g_static_mutex_unlock (&tmdpconfig->access_mutex);

  return TRUE;
 }



gboolean split_and_push_messages (TMDPTCPListener *listener, gchar *msg, GError **error)
{
gchar **docs = NULL,
**docs2 = NULL,
*str = NULL;
gint i, j;
TMDPIdmef *idmef;


static gchar incompletebuf[TMDP_BUFFER_SIZE] = ""; /* this one is used for incomplete messages */
static gboolean incomplete = FALSE; /* this one also */


#ifdef LIBTMDP_DEBUG
  g_fprintf (stderr, "split_and_push_messages called\n");
#endif

g_return_val_if_fail (listener != NULL || msg != NULL, FALSE);

  /* split data if more than one idmef xml doc is received at once */
  docs = g_strsplit (msg, IDMEF_MSG_SUFFIX, 0); <== this one never returns
...
}

Here is a gdb backtrace:

(gdb) info thread
* 4 Thread 32771 (LWP 28020) 0x4025b985 in __pthread_sigsuspend () from /lib/i686/libpthread.so.0
3 Thread 16386 (LWP 28015) 0x403399b4 in malloc_consolidate () from /lib/i686/libc.so.6
2 Thread 32769 (LWP 28014) 0x4039e357 in poll () from /lib/i686/libc.so.6
1 Thread 16384 (LWP 28013) 0x4025b985 in __pthread_sigsuspend () from /lib/i686/libpthread.so.0
(gdb) thread 3
[Switching to thread 3 (Thread 16386 (LWP 28015))]#0 0x403399b4 in malloc_consolidate () from /lib/i686/libc.so.6
(gdb) bt full
#0 0x403399b4 in malloc_consolidate () from /lib/i686/libc.so.6
No symbol table info available.
#1 0x40339007 in _int_malloc () from /lib/i686/libc.so.6
No symbol table info available.
#2 0x40338201 in malloc () from /lib/i686/libc.so.6
No symbol table info available.
#3 0x400f6589 in g_malloc (n_bytes=1077916672) at gmem.c:136
mem = 0x403fb400
#4 0x401058e3 in g_strsplit (string=0x80859e0 "<?xml version=\"1.0\"?>\n<!DOCTYPE IDMEF-Message PUBLIC \"-//IETF//DTD RFC XXXX IDMEF v1.0//EN\" \"idmef-message.dtd\">\n<IDMEF-Message version=\"1.0\"><Alert ident=\"448\"><Analyzer analyzerid=\"1\" model=\"snort\" version=\"2.1.2\" ostype=\"Linux\" osversion=\"2.4.21\"><Node><name>pluto</name></Node></Analyzer><CreateTime ntpstamp=\"0xc45b3eb6.0x2b7e6f71\">2004-05-23T15:16:06Z</CreateTime><Source><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node><Service><name>icmp</name><protocol>icmp:type=8:code=0</protocol></Service></Source><Target><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node></Target><Classification origin=\"vendor-specific\"><name>msg=ICMP PING BSDtype</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>sid=368</name><url>http://www.snort.org/snort-db/sid.html?sid=368</url></Classification><Classification origin=\"vendor-specific\"><name>class=misc-activity</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>priority=3</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>arachNIDS=152</name><url>http://www.whitehats.com/info/IDS152</url></Classification><Assessment><Impact severity=\"high\"/></Assessment><AdditionalData meaning=\"sig_rev\" type=\"string\">4</AdditionalData></Alert></IDMEF-Message>\n<?xml version=\"1.0\"?>\n<!DOCTYPE IDMEF-Message PUBLIC \"-//IETF//DTD RFC XXXX IDMEF v1.0//EN\" \"idmef-message.dtd\">\n<IDMEF-Message version=\"1.0\"><Alert ident=\"449\"><Analyzer analyzerid=\"1\" model=\"snort\" version=\"2.1.2\" ostype=\"Linux\" osversion=\"2.4.21\"><Node><name>pluto</name></Node></Analyzer><CreateTime ntpstamp=\"0xc45b3eb6.0x2bc3a42f\">2004-05-23T15:16:06Z</CreateTime><Source><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node><Service><name>icmp</name><protocol>icmp:type=0:code=0</protocol></Service></Source><Target><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node></Target><Classification origin=\"vendor-specific\"><name>msg=ICMP Echo Reply</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>sid=408</name><url>http://www.snort.org/snort-db/sid.html?sid=408</url></Classification><Classification origin=\"vendor-specific\"><name>class=misc-activity</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>priority=3</name><url>none</url></Classification><Assessment><Impact severity=\"high\"/></Assessment><AdditionalData meaning=\"sig_rev\" type=\"string\">4</AdditionalData></Alert></IDMEF-Message>\n", delimiter=0x4003e3f8 "</IDMEF-Message>", max_tokens=2147483646) at gstrfuncs.c:2160
string_list = (GSList *) 0x0
slist = (GSList *) 0x48
str_array = (gchar **) 0x403fb400
s = (gchar *) 0x8085f1b "</IDMEF-Message>\n<?xml version=\"1.0\"?>\n<!DOCTYPE IDMEF-Message PUBLIC \"-//IETF//DTD RFC XXXX IDMEF v1.0//EN\" \"idmef-message.dtd\">\n<IDMEF-Message version=\"1.0\"><Alert ident=\"449\"><Analyzer analyzerid=\"1\" model=\"snort\" version=\"2.1.2\" ostype=\"Linux\" osversion=\"2.4.21\"><Node><name>pluto</name></Node></Analyzer><CreateTime ntpstamp=\"0xc45b3eb6.0x2bc3a42f\">2004-05-23T15:16:06Z</CreateTime><Source><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node><Service><name>icmp</name><protocol>icmp:type=0:code=0</protocol></Service></Source><Target><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node></Target><Classification origin=\"vendor-specific\"><name>msg=ICMP Echo Reply</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>sid=408</name><url>http://www.snort.org/snort-db/sid.html?sid=408</url></Classification><Classification origin=\"vendor-specific\"><name>class=misc-activity</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>priority=3</name><url>none</url></Classification><Assessment><Impact severity=\"high\"/></Assessment><AdditionalData meaning=\"sig_rev\" type=\"string\">4</AdditionalData></Alert></IDMEF-Message>\n"
n = 0
remainder = (const gchar *) 0x80859e0 "<?xml version=\"1.0\"?>\n<!DOCTYPE IDMEF-Message PUBLIC \"-//IETF//DTD RFC XXXX IDMEF v1.0//EN\" \"idmef-message.dtd\">\n<IDMEF-Message version=\"1.0\"><Alert ident=\"448\"><Analyzer analyzerid=\"1\" model=\"snort\" version=\"2.1.2\" ostype=\"Linux\" osversion=\"2.4.21\"><Node><name>pluto</name></Node></Analyzer><CreateTime ntpstamp=\"0xc45b3eb6.0x2b7e6f71\">2004-05-23T15:16:06Z</CreateTime><Source><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node><Service><name>icmp</name><protocol>icmp:type=8:code=0</protocol></Service></Source><Target><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node></Target><Classification origin=\"vendor-specific\"><name>msg=ICMP PING BSDtype</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>sid=368</name><url>http://www.snort.org/snort-db/sid.html?sid=368</url></Classification><Classification origin=\"vendor-specific\"><name>class=misc-activity</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>priority=3</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>arachNIDS=152</name><url>http://www.whitehats.com/info/IDS152</url></Classification><Assessment><Impact severity=\"high\"/></Assessment><AdditionalData meaning=\"sig_rev\" type=\"string\">4</AdditionalData></Alert></IDMEF-Message>\n<?xml version=\"1.0\"?>\n<!DOCTYPE IDMEF-Message PUBLIC \"-//IETF//DTD RFC XXXX IDMEF v1.0//EN\" \"idmef-message.dtd\">\n<IDMEF-Message version=\"1.0\"><Alert ident=\"449\"><Analyzer analyzerid=\"1\" model=\"snort\" version=\"2.1.2\" ostype=\"Linux\" osversion=\"2.4.21\"><Node><name>pluto</name></Node></Analyzer><CreateTime ntpstamp=\"0xc45b3eb6.0x2bc3a42f\">2004-05-23T15:16:06Z</CreateTime><Source><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node><Service><name>icmp</name><protocol>icmp:type=0:code=0</protocol></Service></Source><Target><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node></Target><Classification origin=\"vendor-specific\"><name>msg=ICMP Echo Reply</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>sid=408</name><url>http://www.snort.org/snort-db/sid.html?sid=408</url></Classification><Classification origin=\"vendor-specific\"><name>class=misc-activity</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>priority=3</name><url>none</url></Classification><Assessment><Impact severity=\"high\"/></Assessment><AdditionalData meaning=\"sig_rev\" type=\"string\">4</AdditionalData></Alert></IDMEF-Message>\n"
#5 0x4003704c in split_and_push_messages (listener=0x8079e20, msg=0x80859e0 "<?xml version=\"1.0\"?>\n<!DOCTYPE IDMEF-Message PUBLIC \"-//IETF//DTD RFC XXXX IDMEF v1.0//EN\" \"idmef-message.dtd\">\n<IDMEF-Message version=\"1.0\"><Alert ident=\"448\"><Analyzer analyzerid=\"1\" model=\"snort\" version=\"2.1.2\" ostype=\"Linux\" osversion=\"2.4.21\"><Node><name>pluto</name></Node></Analyzer><CreateTime ntpstamp=\"0xc45b3eb6.0x2b7e6f71\">2004-05-23T15:16:06Z</CreateTime><Source><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node><Service><name>icmp</name><protocol>icmp:type=8:code=0</protocol></Service></Source><Target><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node></Target><Classification origin=\"vendor-specific\"><name>msg=ICMP PING BSDtype</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>sid=368</name><url>http://www.snort.org/snort-db/sid.html?sid=368</url></Classification><Classification origin=\"vendor-specific\"><name>class=misc-activity</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>priority=3</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>arachNIDS=152</name><url>http://www.whitehats.com/info/IDS152</url></Classification><Assessment><Impact severity=\"high\"/></Assessment><AdditionalData meaning=\"sig_rev\" type=\"string\">4</AdditionalData></Alert></IDMEF-Message>\n<?xml version=\"1.0\"?>\n<!DOCTYPE IDMEF-Message PUBLIC \"-//IETF//DTD RFC XXXX IDMEF v1.0//EN\" \"idmef-message.dtd\">\n<IDMEF-Message version=\"1.0\"><Alert ident=\"449\"><Analyzer analyzerid=\"1\" model=\"snort\" version=\"2.1.2\" ostype=\"Linux\" osversion=\"2.4.21\"><Node><name>pluto</name></Node></Analyzer><CreateTime ntpstamp=\"0xc45b3eb6.0x2bc3a42f\">2004-05-23T15:16:06Z</CreateTime><Source><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node><Service><name>icmp</name><protocol>icmp:type=0:code=0</protocol></Service></Source><Target><Node><Address category=\"ipv4-addr\"><address>127.0.0.1</address></Address></Node></Target><Classification origin=\"vendor-specific\"><name>msg=ICMP Echo Reply</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>sid=408</name><url>http://www.snort.org/snort-db/sid.html?sid=408</url></Classification><Classification origin=\"vendor-specific\"><name>class=misc-activity</name><url>none</url></Classification><Classification origin=\"vendor-specific\"><name>priority=3</name><url>none</url></Classification><Assessment><Impact severity=\"high\"/></Assessment><AdditionalData meaning=\"sig_rev\" type=\"string\">4</AdditionalData></Alert></IDMEF-Message>\n", error=0x405fed30) at tmdp-tcp-connection.c:896
docs = (gchar **) 0x0
docs2 = (gchar **) 0x0
str = (gchar *) 0x0
i = 0
j = 134692952
idmef = (TMDPIdmef *) 0x40259da7
incompletebuf = '\0' <repeats 32767 times>
incomplete = 0
#6 0x40035de5 in conn_input_event_func (iochannel=0x8078b90, condition=G_IO_IN, data=0x808da00) at tmdp-tcp-connection.c:422
tcpconn = (TMDPTCPConnection *) 0x808da00
bytes_read = 2579
status = G_IO_STATUS_NORMAL
error = (GError *) 0x0
tmdpconfig = (TMDPConfig *) 0x8073fc0
#7 0x40111f1f in g_io_unix_dispatch (source=0x8075d10, callback=0x40035944 <conn_input_event_func>, user_data=0x403fb400) at giounix.c:159
buffer_condition = 72
#8 0x400f0bb5 in g_main_dispatch (context=0x804fab8) at gmain.c:1653
i = 0
#9 0x400f1bf8 in g_main_context_dispatch (context=0x8075d10) at gmain.c:2197
No locals.
#10 0x400f1f0d in g_main_context_iterate (context=0x804fab8, block=1, dispatch=1, self=0x80501e8) at gmain.c:2278
max_priority = 2147483647
timeout = -1
some_ready = 0
nfds = 134700304
allocated_nfds = 1073961284
fds = (GPollFD *) 0x8072ad8
#11 0x400f260f in g_main_loop_run (loop=0x80501d8) at gmain.c:2498
self = (GThread *) 0x80501e8
#12 0x4002ed7c in bg_thread (data=0x0) at tmdp.c:376
No locals.
#13 0x40108ac7 in g_thread_create_proxy (data=0x80501e8) at gthread.c:551
No locals.
#14 0x40259a21 in pthread_start_thread () from /lib/i686/libpthread.so.0
No symbol table info available.
#15 0x40259b25 in pthread_start_thread_event () from /lib/i686/libpthread.so.0
No symbol table info available.


As you can see in #3 g_malloc is called with n_bytes=1077916672 (which is 0x403fb400) which I couldn't figure out where this comes from.

Any hint is greatly apreciated!

TIA,
Sandro

_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux