gtkquartz: don't free the string returned by get_bundle_path()

It's statically allocated.
(cherry picked from commit c040b03c2e32a773a4d9cf4019050c2f8a5b91ce)
This commit is contained in:
Michael Natterer
2011-10-22 23:08:32 +02:00
parent 077b366879
commit 88ad614c73

View File

@ -318,24 +318,28 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
* to test for that and remove the last element. * to test for that and remove the last element.
*/ */
static gchar * static const gchar *
get_bundle_path () get_bundle_path (void)
{ {
static gchar *path = NULL; static gchar *path = NULL;
if (path == NULL) if (path == NULL)
{ {
gchar *base;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]); gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
gchar *base;
[pool drain]; [pool drain];
base = g_path_get_basename (resource_path); base = g_path_get_basename (resource_path);
if (strcmp (base, "bin") == 0) if (strcmp (base, "bin") == 0)
path = g_path_get_dirname (resource_path); path = g_path_get_dirname (resource_path);
else else
path = strdup (resource_path); path = strdup (resource_path);
g_free (resource_path); g_free (resource_path);
g_free (base); g_free (base);
} }
return path; return path;
} }
@ -343,12 +347,10 @@ const gchar *
_gtk_get_datadir (void) _gtk_get_datadir (void)
{ {
static gchar *path = NULL; static gchar *path = NULL;
if (path == NULL) if (path == NULL)
{ path = g_build_filename (get_bundle_path (), "share", NULL);
gchar *resource_dir = get_bundle_path ();
path = g_build_filename (resource_dir, "share", NULL);
g_free (resource_dir);
}
return path; return path;
} }
@ -356,12 +358,10 @@ const gchar *
_gtk_get_libdir (void) _gtk_get_libdir (void)
{ {
static gchar *path = NULL; static gchar *path = NULL;
if (path == NULL) if (path == NULL)
{ path = g_build_filename (get_bundle_path (), "lib", NULL);
gchar *resource_dir = get_bundle_path ();
path = g_build_filename (resource_dir, "lib", NULL);
g_free (resource_dir);
}
return path; return path;
} }
@ -369,12 +369,10 @@ const gchar *
_gtk_get_localedir (void) _gtk_get_localedir (void)
{ {
static gchar *path = NULL; static gchar *path = NULL;
if (path == NULL) if (path == NULL)
{ path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
gchar *resource_dir = get_bundle_path ();
path = g_build_filename (resource_dir, "share", "locale", NULL);
g_free (resource_dir);
}
return path; return path;
} }
@ -382,12 +380,10 @@ const gchar *
_gtk_get_sysconfdir (void) _gtk_get_sysconfdir (void)
{ {
static gchar *path = NULL; static gchar *path = NULL;
if (path == NULL) if (path == NULL)
{ path = g_build_filename (get_bundle_path (), "etc", NULL);
gchar *resource_dir = get_bundle_path ();
path = g_build_filename (resource_dir, "etc", NULL);
g_free (resource_dir);
}
return path; return path;
} }
@ -396,4 +392,3 @@ _gtk_get_data_prefix (void)
{ {
return get_bundle_path (); return get_bundle_path ();
} }