Enlightenment CVS committal
Author : raster
Project : e17
Module : libs/evas
Dir : e17/libs/evas/src/modules/loaders/svg
Modified Files:
evas_image_load_svg.c
Log Message:
hooray! librsvg leak!. if you try and load a file that is NOT an svg with
librsvg - and it fails, it does not FREE UP MEMORY - it LEAKS. BAD RSVG. BAd
BAD! ok - a code to explicitly avoid loading anything NOT .svg or .svg.gz!!!!!!
===================================================================
RCS file: /cvs/e/e17/libs/evas/src/modules/loaders/svg/evas_image_load_svg.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -3 -r1.11 -r1.12
--- evas_image_load_svg.c 5 Nov 2006 05:07:53 -0000 1.11
+++ evas_image_load_svg.c 4 Mar 2007 21:17:36 -0000 1.12
@@ -43,9 +43,31 @@
RsvgHandle *rsvg;
RsvgDimensionData dim;
int w, h;
+ char *ext;
if (!file) return 0;
-
+
+ /* ignore all files not called .svg or .svg.gz - because rsvg has a leak
+ * where closing the handle doesn't free mem */
+ ext = strrchr(file, '.');
+ if (!ext) return;
+ if (!strcasecmp(ext, ".gz"))
+ {
+ if (p > file)
+ {
+ ext = p - 1;
+ while ((*p != '.') && (p > file))
+ {
+ p--;
+ }
+ if (p <= file) return 0;
+ if (strcasecmp(p, ".svg.gz")) return 0;
+ }
+ else
+ return 0;
+ }
+ else if (strcasecmp(ext, ".svg")) return 0;
+
getcwd(pcwd, sizeof(pcwd));
strncpy(cwd, file, sizeof(cwd) - 1);
cwd[sizeof(cwd) - 1] = 0;
@@ -64,7 +86,9 @@
im->image = evas_common_image_surface_new(im);
if (!im->image)
{
- rsvg_handle_free(rsvg);
+ rsvg_handle_close(rsvg, NULL);
+ g_object_unref(rsvg);
+// rsvg_handle_free(rsvg);
chdir(pcwd);
return 0;
}
@@ -75,7 +99,11 @@
h = dim.height;
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
{
- rsvg_handle_free(rsvg);
+ evas_common_image_surface_free(im->image);
+ im->image = NULL;
+ rsvg_handle_close(rsvg, NULL);
+ g_object_unref(rsvg);
+// rsvg_handle_free(rsvg);
chdir(pcwd);
return 0;
}
@@ -109,7 +137,9 @@
im->image->w = w;
im->image->h = h;
im->flags |= RGBA_IMAGE_HAS_ALPHA;
- rsvg_handle_free(rsvg);
+ rsvg_handle_close(rsvg, NULL);
+ g_object_unref(rsvg);
+// rsvg_handle_free(rsvg);
chdir(pcwd);
return 1;
}
@@ -119,17 +149,37 @@
evas_image_load_file_data_svg(RGBA_Image *im, const char *file, const char
*key)
{
char cwd[PATH_MAX], pcwd[PATH_MAX], *p;
-
RsvgHandle *rsvg;
RsvgDimensionData dim;
int w, h;
-
cairo_surface_t *surface;
cairo_t *cr;
+ char *ext;
if (!file) return 0;
if (!im->image) return 0;
+ /* ignore all files not called .svg or .svg.gz - because rsvg has a leak
+ * where closing the handle doesn't free mem */
+ ext = strrchr(file, '.');
+ if (!ext) return;
+ if (!strcasecmp(ext, ".gz"))
+ {
+ if (p > file)
+ {
+ ext = p - 1;
+ while ((*p != '.') && (p > file))
+ {
+ p--;
+ }
+ if (p <= file) return 0;
+ if (strcasecmp(p, ".svg.gz")) return 0;
+ }
+ else
+ return 0;
+ }
+ else if (strcasecmp(ext, ".svg")) return 0;
+
getcwd(pcwd, sizeof(pcwd));
strncpy(cwd, file, sizeof(cwd) - 1);
cwd[sizeof(cwd) - 1] = 0;
@@ -151,7 +201,11 @@
h = dim.height;
if ((w < 1) || (h < 1) || (w > 8192) || (h > 8192))
{
- rsvg_handle_free(rsvg);
+ evas_common_image_surface_free(im->image);
+ im->image = NULL;
+ rsvg_handle_close(rsvg, NULL);
+ g_object_unref(rsvg);
+// rsvg_handle_free(rsvg);
chdir(pcwd);
return 0;
}
@@ -190,7 +244,9 @@
{
evas_common_image_surface_free(im->image);
im->image = NULL;
- rsvg_handle_free(rsvg);
+ rsvg_handle_close(rsvg, NULL);
+ g_object_unref(rsvg);
+// rsvg_handle_free(rsvg);
chdir(pcwd);
return 0;
}
@@ -203,7 +259,9 @@
{
evas_common_image_surface_free(im->image);
im->image = NULL;
- rsvg_handle_free(rsvg);
+ rsvg_handle_close(rsvg, NULL);
+ g_object_unref(rsvg);
+// rsvg_handle_free(rsvg);
chdir(pcwd);
return 0;
}
@@ -213,7 +271,9 @@
cairo_surface_destroy(surface);
evas_common_image_surface_free(im->image);
im->image = NULL;
- rsvg_handle_free(rsvg);
+ rsvg_handle_close(rsvg, NULL);
+ g_object_unref(rsvg);
+// rsvg_handle_free(rsvg);
chdir(pcwd);
return 0;
}
@@ -225,7 +285,9 @@
cairo_surface_destroy(surface);
/* need to check if this is required... */
cairo_destroy(cr);
- rsvg_handle_free(rsvg);
+ rsvg_handle_close(rsvg, NULL);
+ g_object_unref(rsvg);
+// rsvg_handle_free(rsvg);
chdir(pcwd);
evas_common_image_set_alpha_sparse(im);
return 1;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs