After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 564677 - app/sheets_dialog_callbacks.c:1504: Memory leak: so
app/sheets_dialog_callbacks.c:1504: Memory leak: so
Status: RESOLVED FIXED
Product: dia
Classification: Other
Component: general
devel
Other All
: Normal normal
: 0.97
Assigned To: Dia maintainers
Dia maintainers
Depends on:
Blocks:
 
 
Reported: 2008-12-15 22:43 UTC by aggro
Modified: 2009-01-11 23:17 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description aggro 2008-12-15 22:43:09 UTC
In file app/sheets_dialog_callbacks.c:1504
Variable "so" allocates memory using g_new0() and then value of the pointer is assigned to som_new->sheet_object, and after that memory allocated by "so" is not released ever. I think the assignment acts like a memcpy, giving the som_new a copy of it. You could probably do the same without allocating so any memory at all, by using the memory allocated by som_new, but I can't tell I fully understand what is going on here. Easy fix probably is to release memory allocated by "so" after the assignment to sheet_object. 

  so = g_new0(SheetObject, 1);
  so->object_type = g_strdup(som->sheet_object.object_type);
  so->description = g_strdup(som->sheet_object.description);
  so->pixmap = som->sheet_object.pixmap;
  so->user_data = som->sheet_object.user_data;
  so->user_data_type = som->sheet_object.user_data_type;
  so->line_break = FALSE;          /* must be false--we don't copy linebreaks */
  so->pixmap_file = g_strdup(som->sheet_object.pixmap_file);
  so->has_icon_on_sheet = som->sheet_object.has_icon_on_sheet;

  som_new = g_new0(SheetObjectMod, 1);
  som_new->sheet_object = *so;

This bug was found using cppcheck: http://cppcheck.wiki.sourceforge.net/
Comment 1 Hans Breuer 2009-01-11 23:17:00 UTC
Thanks, good catch:

2009-01-12  Hans Breuer  <hans@breuer.org>

	* app/sheets_dialog_callbacks.c : don't leak a superfluous SheetObject
	fixes bug #564677