Plug memory leak and avoid using freed memory. Resolve the whole module

2008-08-21  Johan Dahlin  <johan@gnome.org>

    * girepository/girepository.c (g_irepository_require):
    Plug memory leak and avoid using freed memory.
    Resolve the whole module path, here as well.


svn path=/trunk/; revision=441
This commit is contained in:
Johan Dahlin 2008-08-21 16:38:03 +00:00 committed by Johan Dahlin
parent c66c06f048
commit bfb52af903

View File

@ -529,7 +529,6 @@ g_irepository_require (GIRepository *repository,
if (error1) if (error1)
{ {
g_clear_error (&error1); g_clear_error (&error1);
g_free (full_path);
continue; continue;
} }
@ -539,12 +538,12 @@ g_irepository_require (GIRepository *repository,
if (strcmp (typelib_namespace, namespace) != 0) if (strcmp (typelib_namespace, namespace) != 0)
{ {
g_free (full_path);
g_set_error (error, G_IREPOSITORY_ERROR, g_set_error (error, G_IREPOSITORY_ERROR,
G_IREPOSITORY_ERROR_NAMESPACE_MISMATCH, G_IREPOSITORY_ERROR_NAMESPACE_MISMATCH,
"Typelib file %s for namespace '%s' contains " "Typelib file %s for namespace '%s' contains "
"namespace '%s' which doesn't match the file name", "namespace '%s' which doesn't match the file name",
full_path, namespace, typelib_namespace); full_path, namespace, typelib_namespace);
g_free (full_path);
return NULL; return NULL;
} }
break; break;
@ -552,11 +551,11 @@ g_irepository_require (GIRepository *repository,
if (typelib == NULL) if (typelib == NULL)
{ {
g_free (full_path);
g_set_error (error, G_IREPOSITORY_ERROR, g_set_error (error, G_IREPOSITORY_ERROR,
G_IREPOSITORY_ERROR_TYPELIB_NOT_FOUND, G_IREPOSITORY_ERROR_TYPELIB_NOT_FOUND,
"Typelib file for namespace '%s' was not found in search" "Typelib file for namespace '%s' was not found in search"
" path or could not be openened", namespace); " path or could not be openened", namespace);
g_free (full_path);
return NULL; return NULL;
} }
@ -566,19 +565,25 @@ g_irepository_require (GIRepository *repository,
shlib = ((Header *) typelib->data)->shared_library; shlib = ((Header *) typelib->data)->shared_library;
if (shlib) if (shlib)
{ {
gchar *resolved_shlib;
shlib_fname = g_typelib_get_string (typelib, shlib); shlib_fname = g_typelib_get_string (typelib, shlib);
module = g_module_open (shlib_fname, resolved_shlib = g_module_build_path (NULL, shlib_fname);
module = g_module_open (resolved_shlib,
G_MODULE_BIND_LAZY|G_MODULE_BIND_LOCAL); G_MODULE_BIND_LAZY|G_MODULE_BIND_LOCAL);
if (module == NULL) if (module == NULL)
{ {
g_free (full_path);
g_set_error (error, G_IREPOSITORY_ERROR, g_set_error (error, G_IREPOSITORY_ERROR,
G_IREPOSITORY_ERROR_TYPELIB_NOT_FOUND, G_IREPOSITORY_ERROR_TYPELIB_NOT_FOUND,
"Typelib for namespace '%s' references shared library " "Typelib for namespace '%s' references shared library "
"%s, but it could not be openened (%s)", "%s, but it could not be openened (%s)",
namespace, shlib_fname, g_module_error ()); namespace, resolved_shlib, g_module_error ());
g_free (full_path);
g_free (resolved_shlib);
return NULL; return NULL;
} }
g_free (resolved_shlib);
} }
g_hash_table_remove (table, namespace); g_hash_table_remove (table, namespace);