Commit 868888fe authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

fixed a memleak.

2000-02-24  Michael Natterer  <mitch@gimp.org>

	* app/datafiles.c: fixed a memleak.

	* app/gimpbrushlist.c
	* app/gradient.c
	* app/palette.c: use the gimp_path_* functions, cleanups.

	* app/gimpbrushpipe.c: call the "destroy" function of the parent
	class, not of the object class. Fixes a huge memleak on each
	"Refresh".

	* app/gimpbrushpipeP.h
	* app/gimplist.c
	* app/gimpbrush.c: did some cleanups while searching the brush
	memleak.

	* libgimp/gimpenv.c: gimp_path_get_user_writable_dir(): return a
	copy of the string.

	* plug-ins/FractalExplorer/Dialogs.c
	* plug-ins/gfig/gfig.c
	* plug-ins/gflare/gflare.c: g_free() the string returned by
	gimp_path_get_user_writable_dir().
parent a9df0647
2000-02-24 Michael Natterer <mitch@gimp.org>
* app/datafiles.c: fixed a memleak.
* app/gimpbrushlist.c
* app/gradient.c
* app/palette.c: use the gimp_path_* functions, cleanups.
* app/gimpbrushpipe.c: call the "destroy" function of the parent
class, not of the object class. Fixes a huge memleak on each
"Refresh".
* app/gimpbrushpipeP.h
* app/gimplist.c
* app/gimpbrush.c: did some cleanups while searching the brush
memleak.
* libgimp/gimpenv.c: gimp_path_get_user_writable_dir(): return a
copy of the string.
* plug-ins/FractalExplorer/Dialogs.c
* plug-ins/gfig/gfig.c
* plug-ins/gflare/gflare.c: g_free() the string returned by
gimp_path_get_user_writable_dir().
Thu Feb 24 02:20:15 CET 2000 Sven Neumann <sven@gimp.org>
* app/gimprc.c: gimp_parasite_attach() creates a copy of
......
......@@ -15,10 +15,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "gimpbrush.h"
#include "gimpbrushlist.h"
#include "gimpsignal.h"
......@@ -28,30 +28,32 @@
#include "config.h"
#include "libgimp/gimpintl.h"
enum{
enum
{
DIRTY,
RENAME,
LAST_SIGNAL
};
static GimpBrush *gimp_brush_select_brush (PaintCore *paint_core);
static gboolean gimp_brush_want_null_motion (PaintCore *paint_core);
static GimpBrush * gimp_brush_select_brush (PaintCore *paint_core);
static gboolean gimp_brush_want_null_motion (PaintCore *paint_core);
static guint gimp_brush_signals[LAST_SIGNAL];
static GimpObjectClass* parent_class;
static void
gimp_brush_destroy(GtkObject *object)
gimp_brush_destroy (GtkObject *object)
{
GimpBrush* brush=GIMP_BRUSH(object);
GimpBrush *brush = GIMP_BRUSH (object);
if (brush->filename)
g_free(brush->filename);
g_free (brush->filename);
if (brush->name)
g_free(brush->name);
g_free (brush->name);
if (brush->mask)
temp_buf_free(brush->mask);
GTK_OBJECT_CLASS(parent_class)->destroy (object);
temp_buf_free (brush->mask);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
......@@ -81,16 +83,16 @@ gimp_brush_class_init (GimpBrushClass *klass)
}
void
gimp_brush_init(GimpBrush *brush)
gimp_brush_init (GimpBrush *brush)
{
brush->filename = NULL;
brush->name = NULL;
brush->spacing = 20;
brush->mask = NULL;
brush->x_axis.x = 15.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = 15.0;
brush->x_axis.x = 15.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = 15.0;
}
......@@ -98,9 +100,11 @@ GtkType
gimp_brush_get_type (void)
{
static GtkType type = 0;
if(!type)
if (!type)
{
static const GtkTypeInfo info = {
static const GtkTypeInfo info =
{
"GimpBrush",
sizeof (GimpBrush),
sizeof (GimpBrushClass),
......@@ -116,10 +120,12 @@ gimp_brush_get_type (void)
}
GimpBrush *
gimp_brush_new (char *filename)
gimp_brush_new (gchar *filename)
{
GimpBrush *brush=GIMP_BRUSH(gtk_type_new(gimp_brush_get_type ()));
gimp_brush_load(brush, filename);
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
gimp_brush_load (brush, filename);
return brush;
}
......@@ -138,31 +144,35 @@ gimp_brush_want_null_motion (PaintCore *paint_core)
TempBuf *
gimp_brush_get_mask (GimpBrush *brush)
{
g_return_val_if_fail(GIMP_IS_BRUSH(brush), NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->mask;
}
char *
gimp_brush_get_name (GimpBrush *brush)
{
g_return_val_if_fail(GIMP_IS_BRUSH(brush), NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->name;
}
void
gimp_brush_set_name (GimpBrush *brush,
char *name)
gchar *name)
{
g_return_if_fail(GIMP_IS_BRUSH(brush));
if (strcmp(brush->name, name) == 0)
g_return_if_fail (GIMP_IS_BRUSH (brush));
if (strcmp (brush->name, name) == 0)
return;
if (brush->name)
g_free(brush->name);
brush->name = g_strdup(name);
gtk_signal_emit(GTK_OBJECT(brush), gimp_brush_signals[RENAME]);
g_free (brush->name);
brush->name = g_strdup (name);
gtk_signal_emit (GTK_OBJECT (brush), gimp_brush_signals[RENAME]);
}
int
gint
gimp_brush_get_spacing (GimpBrush *brush)
{
g_return_val_if_fail (brush != NULL, 0);
......@@ -173,7 +183,7 @@ gimp_brush_get_spacing (GimpBrush *brush)
void
gimp_brush_set_spacing (GimpBrush *brush,
int spacing)
gint spacing)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH (brush));
......@@ -183,7 +193,7 @@ gimp_brush_set_spacing (GimpBrush *brush,
void
gimp_brush_load (GimpBrush *brush,
char *filename)
gchar *filename)
{
FILE * fp;
......@@ -207,16 +217,16 @@ gimp_brush_load (GimpBrush *brush,
}
int
gint
gimp_brush_load_brush (GimpBrush *brush,
FILE *fp,
char *filename)
gchar *filename)
{
int bn_size;
unsigned char buf [sz_BrushHeader];
gint bn_size;
guchar buf [sz_BrushHeader];
BrushHeader header;
unsigned int * hp;
int i;
guint *hp;
gint i;
/* Read in the header size */
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
......@@ -227,7 +237,7 @@ gimp_brush_load_brush (GimpBrush *brush,
}
/* rearrange the bytes in each unsigned int */
hp = (unsigned int *) &header;
hp = (guint *) &header;
for (i = 0; i < (sz_BrushHeader / 4); i++)
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
......@@ -242,7 +252,6 @@ gimp_brush_load_brush (GimpBrush *brush,
return 0;
}
}
if (header.version == 1)
{
......@@ -252,48 +261,47 @@ gimp_brush_load_brush (GimpBrush *brush,
/* spacing is not defined in version 1 */
header.spacing = 25;
}
/* Read in the brush name */
if ((bn_size = (header.header_size - sz_BrushHeader)))
{
brush->name = (char *) g_malloc (sizeof (char) * bn_size);
brush->name = g_new (gchar, bn_size);
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
{
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gimp_object_destroy (brush);
return 0;
}
}
else
brush->name = g_strdup (_("Unnamed"));
switch (header.version)
{
g_message (_("Error in GIMP brush file...aborting."));
case 1:
case 2:
/* Get a new brush mask */
brush->mask = temp_buf_new (header.width, header.height, header.bytes,
0, 0, NULL);
brush->spacing = header.spacing;
/* set up spacing axis */
brush->x_axis.x = header.width / 2.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = header.height / 2.0;
/* Read the brush mask data */
if ((fread (temp_buf_data (brush->mask), 1, header.width * header.height,
fp)) < header.width * header.height)
g_message (_("GIMP brush file appears to be truncated."));
break;
default:
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
gimp_object_destroy (brush);
return 0;
}
}
else
brush->name = g_strdup (_("Unnamed"));
switch(header.version)
{
case 1:
case 2:
/* Get a new brush mask */
brush->mask = temp_buf_new (header.width, header.height, header.bytes,
0, 0, NULL);
brush->spacing = header.spacing;
/* set up spacing axis */
brush->x_axis.x = header.width / 2.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = header.height / 2.0;
/* Read the brush mask data */
if ((fread (temp_buf_data (brush->mask), 1, header.width * header.height,
fp)) < header.width * header.height)
g_message (_("GIMP brush file appears to be truncated."));
break;
default:
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
gimp_object_destroy (brush);
return 0;
}
return 1;
}
......@@ -15,10 +15,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "gimpbrush.h"
#include "gimpbrushlist.h"
#include "gimpsignal.h"
......@@ -28,30 +28,32 @@
#include "config.h"
#include "libgimp/gimpintl.h"
enum{
enum
{
DIRTY,
RENAME,
LAST_SIGNAL
};
static GimpBrush *gimp_brush_select_brush (PaintCore *paint_core);
static gboolean gimp_brush_want_null_motion (PaintCore *paint_core);
static GimpBrush * gimp_brush_select_brush (PaintCore *paint_core);
static gboolean gimp_brush_want_null_motion (PaintCore *paint_core);
static guint gimp_brush_signals[LAST_SIGNAL];
static GimpObjectClass* parent_class;
static void
gimp_brush_destroy(GtkObject *object)
gimp_brush_destroy (GtkObject *object)
{
GimpBrush* brush=GIMP_BRUSH(object);
GimpBrush *brush = GIMP_BRUSH (object);
if (brush->filename)
g_free(brush->filename);
g_free (brush->filename);
if (brush->name)
g_free(brush->name);
g_free (brush->name);
if (brush->mask)
temp_buf_free(brush->mask);
GTK_OBJECT_CLASS(parent_class)->destroy (object);
temp_buf_free (brush->mask);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
......@@ -81,16 +83,16 @@ gimp_brush_class_init (GimpBrushClass *klass)
}
void
gimp_brush_init(GimpBrush *brush)
gimp_brush_init (GimpBrush *brush)
{
brush->filename = NULL;
brush->name = NULL;
brush->spacing = 20;
brush->mask = NULL;
brush->x_axis.x = 15.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = 15.0;
brush->x_axis.x = 15.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = 15.0;
}
......@@ -98,9 +100,11 @@ GtkType
gimp_brush_get_type (void)
{
static GtkType type = 0;
if(!type)
if (!type)
{
static const GtkTypeInfo info = {
static const GtkTypeInfo info =
{
"GimpBrush",
sizeof (GimpBrush),
sizeof (GimpBrushClass),
......@@ -116,10 +120,12 @@ gimp_brush_get_type (void)
}
GimpBrush *
gimp_brush_new (char *filename)
gimp_brush_new (gchar *filename)
{
GimpBrush *brush=GIMP_BRUSH(gtk_type_new(gimp_brush_get_type ()));
gimp_brush_load(brush, filename);
GimpBrush *brush = GIMP_BRUSH (gtk_type_new (gimp_brush_get_type ()));
gimp_brush_load (brush, filename);
return brush;
}
......@@ -138,31 +144,35 @@ gimp_brush_want_null_motion (PaintCore *paint_core)
TempBuf *
gimp_brush_get_mask (GimpBrush *brush)
{
g_return_val_if_fail(GIMP_IS_BRUSH(brush), NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->mask;
}
char *
gimp_brush_get_name (GimpBrush *brush)
{
g_return_val_if_fail(GIMP_IS_BRUSH(brush), NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->name;
}
void
gimp_brush_set_name (GimpBrush *brush,
char *name)
gchar *name)
{
g_return_if_fail(GIMP_IS_BRUSH(brush));
if (strcmp(brush->name, name) == 0)
g_return_if_fail (GIMP_IS_BRUSH (brush));
if (strcmp (brush->name, name) == 0)
return;
if (brush->name)
g_free(brush->name);
brush->name = g_strdup(name);
gtk_signal_emit(GTK_OBJECT(brush), gimp_brush_signals[RENAME]);
g_free (brush->name);
brush->name = g_strdup (name);
gtk_signal_emit (GTK_OBJECT (brush), gimp_brush_signals[RENAME]);
}
int
gint
gimp_brush_get_spacing (GimpBrush *brush)
{
g_return_val_if_fail (brush != NULL, 0);
......@@ -173,7 +183,7 @@ gimp_brush_get_spacing (GimpBrush *brush)
void
gimp_brush_set_spacing (GimpBrush *brush,
int spacing)
gint spacing)
{
g_return_if_fail (brush != NULL);
g_return_if_fail (GIMP_IS_BRUSH (brush));
......@@ -183,7 +193,7 @@ gimp_brush_set_spacing (GimpBrush *brush,
void
gimp_brush_load (GimpBrush *brush,
char *filename)
gchar *filename)
{
FILE * fp;
......@@ -207,16 +217,16 @@ gimp_brush_load (GimpBrush *brush,
}
int
gint
gimp_brush_load_brush (GimpBrush *brush,
FILE *fp,
char *filename)
gchar *filename)
{
int bn_size;
unsigned char buf [sz_BrushHeader];
gint bn_size;
guchar buf [sz_BrushHeader];
BrushHeader header;
unsigned int * hp;
int i;
guint *hp;
gint i;
/* Read in the header size */
if ((fread (buf, 1, sz_BrushHeader, fp)) < sz_BrushHeader)
......@@ -227,7 +237,7 @@ gimp_brush_load_brush (GimpBrush *brush,
}
/* rearrange the bytes in each unsigned int */
hp = (unsigned int *) &header;
hp = (guint *) &header;
for (i = 0; i < (sz_BrushHeader / 4); i++)
hp [i] = (buf [i * 4] << 24) + (buf [i * 4 + 1] << 16) +
(buf [i * 4 + 2] << 8) + (buf [i * 4 + 3]);
......@@ -242,7 +252,6 @@ gimp_brush_load_brush (GimpBrush *brush,
return 0;
}
}
if (header.version == 1)
{
......@@ -252,48 +261,47 @@ gimp_brush_load_brush (GimpBrush *brush,
/* spacing is not defined in version 1 */
header.spacing = 25;
}
/* Read in the brush name */
if ((bn_size = (header.header_size - sz_BrushHeader)))
{
brush->name = (char *) g_malloc (sizeof (char) * bn_size);
brush->name = g_new (gchar, bn_size);
if ((fread (brush->name, 1, bn_size, fp)) < bn_size)
{
g_message (_("Error in GIMP brush file...aborting."));
fclose (fp);
gimp_object_destroy (brush);
return 0;
}
}
else
brush->name = g_strdup (_("Unnamed"));
switch (header.version)
{
g_message (_("Error in GIMP brush file...aborting."));
case 1:
case 2:
/* Get a new brush mask */
brush->mask = temp_buf_new (header.width, header.height, header.bytes,
0, 0, NULL);
brush->spacing = header.spacing;
/* set up spacing axis */
brush->x_axis.x = header.width / 2.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = header.height / 2.0;
/* Read the brush mask data */
if ((fread (temp_buf_data (brush->mask), 1, header.width * header.height,
fp)) < header.width * header.height)
g_message (_("GIMP brush file appears to be truncated."));
break;
default:
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
gimp_object_destroy (brush);
return 0;
}
}
else
brush->name = g_strdup (_("Unnamed"));
switch(header.version)
{
case 1:
case 2:
/* Get a new brush mask */
brush->mask = temp_buf_new (header.width, header.height, header.bytes,
0, 0, NULL);
brush->spacing = header.spacing;
/* set up spacing axis */
brush->x_axis.x = header.width / 2.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = header.height / 2.0;
/* Read the brush mask data */
if ((fread (temp_buf_data (brush->mask), 1, header.width * header.height,
fp)) < header.width * header.height)
g_message (_("GIMP brush file appears to be truncated."));
break;
default:
g_message (_("Unknown brush format version #%d in \"%s\"\n"),
header.version, filename);
fclose (fp);
gimp_object_destroy (brush);
return 0;
}
return 1;
}
......@@ -39,11 +39,11 @@
#include "libgimp/gimpmath.h"
#include "libgimp/parasiteio.h"
static GimpBrushClass* gimp_brush_class;
static GtkObjectClass* gimp_object_class;
static GimpBrushClass *gimp_brush_class;
static GimpBrushPixmapClass *gimp_brush_pixmap_class;
static GimpBrush *gimp_brush_pixmap_select_brush (PaintCore *paint_core);
static gboolean gimp_brush_pixmap_want_null_motion (PaintCore *paint_core);
static GimpBrush *gimp_brush_pixmap_select_brush (PaintCore *paint_core);
static gboolean gimp_brush_pixmap_want_null_motion (PaintCore *paint_core);
static void
gimp_brush_pixmap_destroy (GtkObject *object)
......@@ -53,10 +53,11 @@ gimp_brush_pixmap_destroy (GtkObject *object)
g_return_if_fail (GIMP_IS_BRUSH_PIXMAP (object));
pixmap = GIMP_BRUSH_PIXMAP (object);
temp_buf_free (pixmap->pixmap_mask);
(* GTK_OBJECT_CLASS (gimp_object_class)->destroy) (object);
if (GTK_OBJECT_CLASS (gimp_brush_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_brush_class)->destroy) (object);
}
static void
......@@ -70,8 +71,8 @@ gimp_brush_pixmap_class_init (GimpBrushPixmapClass *klass)
gimp_brush_class = gtk_type_class (gimp_brush_get_type ());
object_class->destroy = gimp_brush_pixmap_destroy;
brush_class->select_brush = gimp_brush_pixmap_select_brush;
object_class->destroy = gimp_brush_pixmap_destroy;
brush_class->select_brush = gimp_brush_pixmap_select_brush;
brush_class->want_null_motion = gimp_brush_pixmap_want_null_motion;
}
......@@ -193,10 +194,10 @@ gimp_brush_pixmap_want_null_motion (PaintCore *paint_core)
}
static void
gimp_brush_pipe_destroy(GtkObject *object)
gimp_brush_pipe_destroy (GtkObject *object)
{
GimpBrushPipe *pipe;
int i;
gint i;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_BRUSH_PIPE (object));
......@@ -207,68 +208,74 @@ gimp_brush_pipe_destroy(GtkObject *object)
g_free (pipe->stride);
for (i = 1; i < pipe->nbrushes; i++)
gimp_object_destroy (pipe->brushes[i]);
gtk_object_unref (GTK_OBJECT (pipe->brushes[i]));
g_free (pipe->brushes);
g_free (pipe->select);
g_free (pipe->index);
if (GTK_OBJECT_CLASS (gimp_object_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_object_class)->destroy) (object);
if (GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy)
(* GTK_OBJECT_CLASS (gimp_brush_pixmap_class)->destroy) (object);
}
static void
gimp_brush_pipe_class_init (GimpBrushPipeClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (klass);
gimp_object_class = gtk_type_class (GIMP_TYPE_OBJECT);
object_class->destroy = gimp_brush_pipe_destroy;
gimp_brush_pixmap_class = gtk_type_class (GIMP_TYPE_BRUSH_PIXMAP);
object_class->destroy = gimp_brush_pipe_destroy;
}
void
gimp_brush_pipe_init (GimpBrushPipe *pipe)
{
pipe->dimension = 0;
pipe->rank = NULL;
pipe->nbrushes = 0;
pipe->select = NULL;
pipe->index = NULL;
pipe->rank = NULL;
pipe->nbrushes = 0;
pipe->select = NULL;
pipe->index = NULL;
}
GtkType
gimp_brush_pipe_get_type (void)
{
static GtkType type=0;
if (!type){
GtkTypeInfo info={
"GimpBrushPipe",
sizeof (GimpBrushPipe),
sizeof (GimpBrushPipeClass),
(GtkClassInitFunc) gimp_brush_pipe_class_init,
(GtkObjectInitFunc) gimp_brush_pipe_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL};
type = gtk_type_unique (GIMP_TYPE_BRUSH_PIXMAP, &info);
}
static GtkType type = 0;
if (!type)
{
GtkTypeInfo info =
{
"GimpBrushPipe",
sizeof (GimpBrushPipe),