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



On 18 Jan 1999, Owen Taylor wrote:

> 
> Ken Stebbings <kens@ecg.csg.mot.com> writes:
> 
> > I just got glib/gtk+ 1.13 and I still have problems relating to memory
> > management, but hopefully it will be easier to track them down now. 
> > When I compiled and ran testgtk, it coredumps right away:
> > 
> > (gdb) bt
> > #0  0xc009f60c in memorymap ()
> > #1  0xc009d654 in free ()
> > #2  0xc1e76910 in g_free (mem=0x40003540) at gmem.c:394
> > #3  0xc238a7dc in gtk_label_set_text_internal (label=0x40026948, 
> >     str=0x40027198 "Gtk+ v1.1.13", str_wc=0x40027158) at gtklabel.c:224
> > #4  0xc238aaec in gtk_label_set_text (label=0x40026948, 
> >     str=0x7b03af08 "Gtk+ v1.1.13") at gtklabel.c:262
> > #5  0xc238a6ec in gtk_label_new (str=0x40026948 "@\002aČ") at
> > gtklabel.c:213
> > #6  0x25bb0 in create_main_window () at testgtk.c:8433
> > #7  0x25fdc in main (argc=1, argv=0x7b03ab84) at testgtk.c:8505
> > (gdb) 
> 
> OK, this looks promising. Could you try the follwing
> patch and see if it fixes the problem?
> 
>                                         Owen
> 
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/gnome/gtk+/ChangeLog,v
> retrieving revision 1.933
> diff -u -r1.933 ChangeLog
> --- ChangeLog	1999/01/18 19:27:39	1.933
> +++ ChangeLog	1999/01/18 20:43:00
> @@ -1,3 +1,9 @@
> +Mon Jan 18 15:46:14 1999  Owen Taylor  <otaylor@redhat.com>
> +
> +	* gtk/gtklabel.c (gtk_label_init): Initialize
> +	label->label_wc. (We allocate labels from
> +	a memchunk)
> +

in what way should this be memchunk related (apart from the
fact that _init functions should *always* initialize *all* fields
correctly)?

gtk_type_new() does:
  if (node->mem_chunk)
    tobject = g_mem_chunk_alloc0 (node->mem_chunk);
  else
    tobject = g_malloc0 (node->type_info.object_size);
and from gmem.c:
gpointer
g_mem_chunk_alloc0 (GMemChunk *mem_chunk)
{
  gpointer mem;

  mem = g_mem_chunk_alloc (mem_chunk);
  if (mem)
    {
      GRealMemChunk *rmem_chunk = (GRealMemChunk*) mem_chunk;

      memset (mem, 0, rmem_chunk->atom_size);
    }

  return mem;
}

so independant from whether memchunks are used for the object allocation
or not, the memory itself is always initialized with 0s.

>  Mon Jan 18 14:26:17 1999  Owen Taylor  <otaylor@redhat.com>
>  
>  	* docs/Changes-1.2.txt: Some editing, a little more
> Index: gtk/gtklabel.c
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/gtklabel.c,v
> retrieving revision 1.42
> diff -u -r1.42 gtklabel.c
> --- gtklabel.c	1999/01/17 19:02:53	1.42
> +++ gtklabel.c	1999/01/18 20:43:00
> @@ -192,10 +192,13 @@
>    GTK_WIDGET_SET_FLAGS (label, GTK_NO_WINDOW);
>    
>    label->label = NULL;
> +  label->label_wc = NULL;
> +  label->pattern = NULL;
> +
>    label->words = NULL;
> +
>    label->max_width = 0;
>    label->jtype = GTK_JUSTIFY_CENTER;
> -  label->pattern = NULL;
>    label->wrap = FALSE;
>    
>    gtk_label_set_text (label, "");
> 
> 
> -- 
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
> 
> 

---
ciaoTJ



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