Details

[Home]

Issue of the Implementation # D0002

Brief

Invocation of the interface "g_hook_free" fails in certain conditions

Detailed Description

Invocation of the interface g_hook_free fails if "finalize_hook" member of the struct GHookList is set to NULL. According to the documentation of the interface g_hook_free: Calls the GHookList hook_free function if it exists, and frees the memory allocated for the GHook. In this excerpt the phrase "hook_free function" should be read as "finalize_hook function", since the actual interface called in the source code is the "finalize_hook", while the "hook_free" identifier is not used anywhere in the code.

Problem location(s) in the standard

Linux Standard Base Desktop Specification 3.1, Chapter 12. Libraries, 12.2 Interfaces for libglib-2.0; http://www.gtk.org/api/2.6/glib/glib-Hook-Functions.html#g-hook-free

Example

#include <glib.h>

int main()
{
    GHookList hookList;
    g_hook_list_init(&hookList, sizeof(GHook));
    hookList.finalize_hook = NULL;
    GHook* hook = g_hook_alloc(&hookList);
    g_hook_free(&hookList, hook);
}

Possible solutions

The "finalize_hook" function pointer should be verified for NULL before invocation in "g_hook_free()".

--- glib-2.14.0/glib/ghook.c
+++ glib-2.14.0-fixed/glib/ghook.c
@@ -130,7 +130,8 @@
   g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
   g_return_if_fail (!G_HOOK_IN_CALL (hook));

-  hook_list->finalize_hook (hook_list, hook);
+  if(hook_list->finalize_hook != NULL)
+      hook_list->finalize_hook (hook_list, hook);
   g_slice_free1 (hook_list->hook_size, hook);
 }

Component

gtk-glib 2.6.2 or later

Accepted

Gnome Bugzilla 476849

Status

Fixed in gtk-glib - 2.14.2

[Home]