GNOME Bugzilla – Bug 585521
wrong size allocation in RecentManager::add_item
Last modified: 2009-06-16 16:58:04 UTC
it should be sizeof(*glib) instead of sizeof(glib), this patch fixes a crash in subtitleeditor and probably other applications that use RecentManager
Created attachment 136385 [details] patch to fix RecentManager::add_item
- c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(gchar))); + c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(*gchar))); I asume that sizeof(*gchar) is the same as sizeof(gchar*), in which case this makes sense. This is likely to be a problem on 64-bit systems, right?
I think sizeof(*gchar) is just a syntax error, but sizeof(gchar*) is probably what was meant. sizeof(gchar) is always 1 and definitely wrong in this context. Alternatively, one may just use g_new().
sorry i made several typos, anyway i meant it should be sizeof(gchar*) and yes i have 64-bit system
Comment on attachment 136385 [details] patch to fix RecentManager::add_item >--- gtkmm-2.16.0/gtk/src/recentmanager.ccg 2009-06-12 04:32:58.000000000 +0100 >+++ gtkmm-2.16.0-patched/gtk/src/recentmanager.ccg 2009-06-12 05:28:12.000000000 +0100 >@@ -34,7 +34,7 @@ bool RecentManager::add_item(const Glib: > c_data.mime_type = const_cast<gchar*>(data.mime_type.c_str()); > c_data.app_name = const_cast<gchar*>(data.app_name.c_str()); > c_data.app_exec = const_cast<gchar*>(data.app_exec.c_str()); >- c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(gchar))); >+ c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(gchar*))); > for(unsigned int i = 0; i < data.groups.size(); ++ i) > c_data.groups[i] = const_cast<gchar*>(data.groups[i].c_str()); > c_data.groups[data.groups.size()] = NULL;
Just to preempt confusion: This a bug on any machine and in no way limited to 64 bit systems. On a side note, the code excerpt looks suspiciously like something that needs to be reworked anyway. Reasonable uses of g_malloc() in non-generated wrapper code are rare.
Applied in git Thanks. Please patch the ChangeLog in future.