Commit c5237bac authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

libgimpbase/gimpenv.c (gimp_toplevel_directory) plugged memory leaks.

2005-11-16  Sven Neumann  <sven@gimp.org>

	* libgimpbase/gimpenv.c (gimp_toplevel_directory)
	* app/widgets/gimpcolormapeditor.c (gimp_colormap_editor_draw_cell):
	plugged memory leaks.
parent 218c03c7
2005-11-16 Sven Neumann <sven@gimp.org>
* libgimpbase/gimpenv.c (gimp_toplevel_directory)
* app/widgets/gimpcolormapeditor.c (gimp_colormap_editor_draw_cell):
plugged memory leaks.
2005-11-16 Michael Natterer <mitch@gimp.org>
* app/core/gimplayer.c (gimp_layer_convert):
......
......@@ -494,7 +494,7 @@ gimp_colormap_editor_draw_cell (GimpColormapEditor *editor,
gimage = GIMP_IMAGE_EDITOR (editor)->gimage;
cellsize = editor->cellsize;
row = g_new (guchar, cellsize * 3);
row = g_alloca (cellsize * 3);
x = (col % editor->xn) * cellsize;
y = (col / editor->xn) * cellsize;
......
......@@ -39,8 +39,8 @@
#ifdef G_OS_WIN32
#define STRICT
#define WIN32_LEAN_AND_MEAN /* without it DATADIR in objidl.h will collide */
#include <windows.h> /* For GetModuleFileName */
#define WIN32_LEAN_AND_MEAN /* without it DATADIR in objidl.h will collide */
#include <windows.h> /* For GetModuleFileName */
#include <io.h>
#ifndef S_IWUSR
# define S_IWUSR _S_IWRITE
......@@ -50,8 +50,8 @@
#define S_IWOTH (_S_IWRITE>>6)
#endif
#ifndef S_ISDIR
# define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
# define S_ISDIR(mode) __S_ISTYPE((mode), _S_IFDIR)
# define __S_ISTYPE(mode, mask) (((mode) & _S_IFMT) == (mask))
# define S_ISDIR(mode) __S_ISTYPE((mode), _S_IFDIR)
#endif
#define uid_t gint
#define gid_t gint
......@@ -99,10 +99,10 @@ gimp_env_init (gboolean plug_in)
{
gchar *tmp = g_strconcat (libdir, ":", ldpath, NULL);
g_setenv ("LD_LIBRARY_PATH", tmp, TRUE);
g_setenv ("LD_LIBRARY_PATH", tmp, TRUE);
g_free (tmp);
}
}
else
{
g_setenv ("LD_LIBRARY_PATH", libdir, TRUE);
......@@ -157,58 +157,58 @@ gimp_directory (void)
gimp_dir = g_strdup (env_gimp_dir);
}
else
{
if (home_dir)
{
gimp_dir = g_build_filename (home_dir,
{
if (home_dir)
{
gimp_dir = g_build_filename (home_dir,
env_gimp_dir,
NULL);
}
else
{
gimp_dir = g_build_filename (gimp_data_directory (),
}
else
{
gimp_dir = g_build_filename (gimp_data_directory (),
env_gimp_dir, NULL);
}
}
}
}
}
else
{
if (home_dir)
{
gimp_dir = g_build_filename (home_dir, GIMPDIR, NULL);
}
{
gimp_dir = g_build_filename (home_dir, GIMPDIR, NULL);
}
else
{
gchar *user_name = g_strdup (g_get_user_name ());
gchar *subdir_name;
{
gchar *user_name = g_strdup (g_get_user_name ());
gchar *subdir_name;
#ifdef G_OS_WIN32
gchar *p = user_name;
while (*p)
{
/* Replace funny characters in the user name with an
* underscore. The code below also replaces some
* characters that in fact are legal in file names, but
* who cares, as long as the definitely illegal ones are
* caught.
*/
if (!g_ascii_isalnum (*p) && !strchr ("-.,@=", *p))
*p = '_';
p++;
}
gchar *p = user_name;
while (*p)
{
/* Replace funny characters in the user name with an
* underscore. The code below also replaces some
* characters that in fact are legal in file names, but
* who cares, as long as the definitely illegal ones are
* caught.
*/
if (!g_ascii_isalnum (*p) && !strchr ("-.,@=", *p))
*p = '_';
p++;
}
#endif
#ifndef G_OS_WIN32
g_message ("warning: no home directory.");
g_message ("warning: no home directory.");
#endif
subdir_name = g_strconcat (GIMPDIR ".", user_name, NULL);
gimp_dir = g_build_filename (gimp_data_directory (),
subdir_name,
subdir_name = g_strconcat (GIMPDIR ".", user_name, NULL);
gimp_dir = g_build_filename (gimp_data_directory (),
subdir_name,
NULL);
g_free (user_name);
g_free (subdir_name);
}
g_free (user_name);
g_free (subdir_name);
}
}
return gimp_dir;
......@@ -233,81 +233,84 @@ gimp_personal_rc_file (const gchar *basename)
return g_build_filename (gimp_directory (), basename, NULL);
}
gchar *
static const gchar *
gimp_toplevel_directory (void)
{
#ifdef G_OS_WIN32
/* Figure it out from the executable name */
static gchar *toplevel = NULL;
gchar *filename;
gchar *sep1, *sep2;
if (toplevel)
return toplevel;
if (G_WIN32_HAVE_WIDECHAR_API ())
{
wchar_t w_filename[MAX_PATH];
if (GetModuleFileNameW (NULL, w_filename, G_N_ELEMENTS (w_filename)) == 0)
g_error ("GetModuleFilenameW failed");
filename = g_utf16_to_utf8 (w_filename, -1, NULL, NULL, NULL);
if (filename == NULL)
g_error ("Converting module filename to UTF-8 failed");
}
else
{
gchar cp_filename[MAX_PATH];
if (GetModuleFileNameA (NULL, cp_filename, G_N_ELEMENTS (cp_filename)) == 0)
g_error ("GetModuleFilenameA failed");
filename = g_locale_to_utf8 (cp_filename, -1, NULL, NULL, NULL);
if (filename == NULL)
g_error ("Converting module filename to UTF-8 failed");
}
/* If the executable file name is of the format
* <foobar>\bin\*.exe or
* <foobar>\lib\gimp\GIMP_API_VERSION\plug-ins\*.exe, use <foobar>.
* Otherwise, use the directory where the executable is.
*/
sep1 = strrchr (filename, '\\');
*sep1 = '\0';
sep2 = strrchr (filename, '\\');
if (sep2 != NULL)
{
if (g_ascii_strcasecmp (sep2 + 1, "bin") == 0)
{
*sep2 = '\0';
}
else
{
gchar test[MAX_PATH];
g_snprintf (test, sizeof (test) - 1,
"\\lib\\gimp\\%s\\plug-ins", GIMP_API_VERSION);
if (strlen (filename) > strlen (test) &&
g_ascii_strcasecmp (filename + strlen (filename) - strlen (test),
test) == 0)
{
filename[strlen (filename) - strlen (test)] = '\0';
}
}
}
toplevel = filename;
return toplevel;
#ifdef G_OS_WIN32
{
/* Figure it out from the executable name */
gchar *filename;
gchar *sep1, *sep2;
if (G_WIN32_HAVE_WIDECHAR_API ())
{
wchar_t w_filename[MAX_PATH];
if (GetModuleFileNameW (NULL,
w_filename, G_N_ELEMENTS (w_filename)) == 0)
g_error ("GetModuleFilenameW failed");
filename = g_utf16_to_utf8 (w_filename, -1, NULL, NULL, NULL);
if (filename == NULL)
g_error ("Converting module filename to UTF-8 failed");
}
else
{
gchar cp_filename[MAX_PATH];
if (GetModuleFileNameA (NULL,
cp_filename, G_N_ELEMENTS (cp_filename)) == 0)
g_error ("GetModuleFilenameA failed");
filename = g_locale_to_utf8 (cp_filename, -1, NULL, NULL, NULL);
if (filename == NULL)
g_error ("Converting module filename to UTF-8 failed");
}
/* If the executable file name is of the format
* <foobar>\bin\*.exe or
* <foobar>\lib\gimp\GIMP_API_VERSION\plug-ins\*.exe, use <foobar>.
* Otherwise, use the directory where the executable is.
*/
sep1 = strrchr (filename, '\\');
*sep1 = '\0';
sep2 = strrchr (filename, '\\');
if (sep2 != NULL)
{
if (g_ascii_strcasecmp (sep2 + 1, "bin") == 0)
{
*sep2 = '\0';
}
else
{
gchar test[MAX_PATH];
g_snprintf (test, sizeof (test) - 1,
"\\lib\\gimp\\%s\\plug-ins", GIMP_API_VERSION);
if (strlen (filename) > strlen (test) &&
g_ascii_strcasecmp (filename + strlen (filename) - strlen (test),
test) == 0)
{
filename[strlen (filename) - strlen (test)] = '\0';
}
}
}
toplevel = filename;
}
#else
return _gimp_reloc_find_prefix (PREFIX);
toplevel = _gimp_reloc_find_prefix (PREFIX);
#endif
return toplevel;
}
/**
......@@ -489,9 +492,9 @@ gimp_path_runtime_fix (gchar **path)
*/
p = *path;
*path = g_strconcat (gimp_toplevel_directory (),
"\\",
*path + strlen (PREFIX "/"),
NULL);
"\\",
*path + strlen (PREFIX "/"),
NULL);
g_free (p);
}
/* Replace forward slashes with backslashes, just for
......@@ -507,22 +510,22 @@ gimp_path_runtime_fix (gchar **path)
gchar *p = *path;
if (!g_path_is_absolute (p))
{
*path = g_build_filename (gimp_toplevel_directory (),
*path, NULL);
*path = g_build_filename (gimp_toplevel_directory (), *path, NULL);
g_free (p);
}
#else
gchar *p;
if (strncmp (*path, PREFIX G_DIR_SEPARATOR_S, strlen (PREFIX G_DIR_SEPARATOR_S)) == 0)
if (strncmp (*path, PREFIX G_DIR_SEPARATOR_S,
strlen (PREFIX G_DIR_SEPARATOR_S)) == 0)
{
/* This is a compile-time entry. Replace the path with the
* real one on this machine.
*/
p = *path;
*path = g_build_filename (gimp_toplevel_directory (),
*path + strlen (PREFIX G_DIR_SEPARATOR_S),
NULL);
*path + strlen (PREFIX G_DIR_SEPARATOR_S),
NULL);
g_free (p);
}
#endif
......@@ -540,9 +543,9 @@ gimp_path_runtime_fix (gchar **path)
**/
GList *
gimp_path_parse (const gchar *path,
gint max_paths,
gboolean check,
GList **check_failed)
gint max_paths,
gboolean check,
GList **check_failed)
{
const gchar *home;
gchar **patharray;
......@@ -563,28 +566,28 @@ gimp_path_parse (const gchar *path,
GString *dir;
if (! patharray[i])
break;
break;
#ifndef G_OS_WIN32
if (*patharray[i] == '~')
{
dir = g_string_new (home);
g_string_append (dir, patharray[i] + 1);
}
{
dir = g_string_new (home);
g_string_append (dir, patharray[i] + 1);
}
else
#endif
{
gimp_path_runtime_fix (&patharray[i]);
dir = g_string_new (patharray[i]);
}
{
gimp_path_runtime_fix (&patharray[i]);
dir = g_string_new (patharray[i]);
}
if (check)
exists = g_file_test (dir->str, G_FILE_TEST_IS_DIR);
if (exists)
list = g_list_prepend (list, g_strdup (dir->str));
list = g_list_prepend (list, g_strdup (dir->str));
else if (check_failed)
fail_list = g_list_prepend (fail_list, g_strdup (dir->str));
fail_list = g_list_prepend (fail_list, g_strdup (dir->str));
g_string_free (dir, TRUE);
}
......@@ -620,14 +623,14 @@ gimp_path_to_str (GList *path)
gchar *dir = list->data;
if (str)
{
g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
g_string_append (str, dir);
}
{
g_string_append_c (str, G_SEARCHPATH_SEPARATOR);
g_string_append (str, dir);
}
else
{
str = g_string_new (dir);
}
{
str = g_string_new (dir);
}
}
if (str)
......@@ -686,17 +689,17 @@ gimp_path_get_user_writable_dir (GList *path)
*/
if (!err && S_ISDIR (filestat.st_mode) &&
((filestat.st_mode & S_IWUSR) ||
((filestat.st_mode & S_IWUSR) ||
((filestat.st_mode & S_IWGRP) &&
(euid != filestat.st_uid)) ||
((filestat.st_mode & S_IWGRP) &&
(euid != filestat.st_uid)) ||
((filestat.st_mode & S_IWOTH) &&
(euid != filestat.st_uid) &&
(egid != filestat.st_gid))))
{
return g_strdup (dir);
}
((filestat.st_mode & S_IWOTH) &&
(euid != filestat.st_uid) &&
(egid != filestat.st_gid))))
{
return g_strdup (dir);
}
}
return NULL;
......@@ -711,7 +714,7 @@ gimp_env_get_dir (const gchar *gimp_env_name,
if (env)
{
if (! g_path_is_absolute (env))
g_error ("%s environment variable should be an absolute path.",
g_error ("%s environment variable should be an absolute path.",
gimp_env_name);
return g_strdup (env);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment