Re: [gtk-list] Re: Any problems with malloc functions?



I think I have found at least part of the problem I am having:  I traced
the program execution to here:

(gdb) bt
#0  gdk_wcstombs (src=0x400297f8) at gdkim.c:1481
#1  0x7abca124 in gtk_label_paint_word (label=0x40026eac, x=55, y=3,
word=0x4002d564, area=0x7b03b642) at gtklabel.c:886
#2  0x7abca7e0 in gtk_label_expose (widget=0x40026eac, event=0x7b03b638)
at gtklabel.c:941
#3  0x7acfc6f4 in gtk_marshal_BOOL__POINTER (object=0x40026eac,
func=0x7aa588fa, func_data=0x0, args=0x7b03b738) at gtkmarshal.c:30
#4  0x7ac5f688 in gtk_signal_real_emit (object=0x40026eac, signal_id=25,
params=0x7b03b738) at gtksignal.c:1460
#5  0x7ac5ab7c in gtk_signal_emit (object=0x40026eac, signal_id=25) at
gtksignal.c:528
#6  0x7ace43c4 in gtk_widget_event (widget=0x40026eac, event=0x7b03b638)
at gtkwidget.c:2729
#7  0x7aaf40f0 in gtk_button_expose (widget=0x40029328,
event=0x40033ec8) at gtkbutton.c:655
#8  0x7acfc6f4 in gtk_marshal_BOOL__POINTER (object=0x40029328,
func=0x7aa57912, func_data=0x0, args=0x7b03b178) at gtkmarshal.c:30
#9  0x7ac5f688 in gtk_signal_real_emit (object=0x40029328, signal_id=25,
params=0x7b03b178) at gtksignal.c:1460
#10 0x7ac5ab7c in gtk_signal_emit (object=0x40029328, signal_id=25) at
gtksignal.c:528
#11 0x7ace43c4 in gtk_widget_event (widget=0x40029328, event=0x40033ec8)
at gtkwidget.c:2729
#12 0x7abe5288 in gtk_main_do_event (event=0x40033ec8) at gtkmain.c:676
#13 0x7ae6ab14 in gdk_event_dispatch (source_data=0x0,
current_time=0x7b03aef0, user_data=0x0) at gdkevents.c:2061
#14 0x7ad41318 in g_main_dispatch (current_time=0x7b03aef0) at
gmain.c:640
#15 0x7ad418c0 in g_main_iterate (block=1073782528, dispatch=1) at
gmain.c:829
#16 0x7ad41b60 in g_main_run (loop=0x40032d08) at gmain.c:887
#17 0x7abe45ac in gtk_main () at gtkmain.c:456
#18 0x3bc70 in main (argc=1, argv=0x7b03ab94) at testgtk.c:8507
(gdb)

In the function gdk_wcstombs, the call to XwcTextListToTextProperty
fails, and gdk_wcstombs returns null.  Bingo, a free to a non-allocated
pointer in gtk_label_paint_word.  Here is the function:

/*
 * gdk_wcstombs 
 *
 * Returns a multi-byte string converted from the specified array
 * of wide characters. The string is newly allocated. The array of
 * wide characters must be null-terminated. If the conversion is
 * failed, it returns NULL.
 */
gchar *
gdk_wcstombs (const GdkWChar *src)
{
  gchar *mbstr;
    
  if (gdk_use_mb)
    {
      XTextProperty tpr;
    
      if (sizeof(wchar_t) != sizeof(GdkWChar))
    	{
    	  gint i;
    	  wchar_t *src_alt;
    	  for (i=0; src[i]; i++);
    	  src_alt = g_new (wchar_t, i+1);
    	  for (; i>=0; i--)
    	    src_alt[i] = src[i];
    	  if (XwcTextListToTextProperty (gdk_display, &src_alt, 1,
XTextStyle, &tpr)
    	      != Success)
    	    {
    	      g_free (src_alt);
    	      return NULL;
    	    }
    	  g_free (src_alt);
    	}
      else
    	{
***    	  if (XwcTextListToTextProperty (gdk_display, (wchar_t**)&src,
1,
    					 XTextStyle, &tpr) != Success)
    	    {
    	      return NULL;
    	    }
    	}
      /*
       * We must copy the string into an area allocated by glib, because
       * the string 'tpr.value' must be freed by XFree().
       */
      mbstr = g_strdup(tpr.value);
      XFree (tpr.value);
    }
  else
    {
      gint length = 0;
      gint i;
    
      while (src[length] != 0)
    	length++;
      
      mbstr = g_new (gchar, length + 1);
    
      for (i=0; i<length+1; i++)
    	mbstr[i] = src[i];
    }
    
  return mbstr;
}

The line marked with the *** is the line that is failing.  I don't have
the xlib programming books with me right now, so I can't look up what
this function does.  I looked at all the arguments and none are illegal
(null).  I couldn't really see any useful info in them, so I'm not
sending them here.  Anyone have any ideas/background that could help?

Thanks,
Ken



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