From 8fedd906a88ff12dc3bc425d710db39a40b5d2ca Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 20 Jan 2013 17:54:58 +0100 Subject: Fixed memory leaks (bzr r12050) --- src/trace/imagemap.cpp | 82 +++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 37 deletions(-) (limited to 'src/trace') diff --git a/src/trace/imagemap.cpp b/src/trace/imagemap.cpp index c5a6bc2b5..a8d8a8c8f 100644 --- a/src/trace/imagemap.cpp +++ b/src/trace/imagemap.cpp @@ -192,16 +192,18 @@ PackedPixelMap *PackedPixelMapCreate(int width, int height) /** fields **/ me->width = width; me->height = height; - me->pixels = (unsigned long *) - malloc(sizeof(unsigned long) * width * height); - me->rows = (unsigned long **) - malloc(sizeof(unsigned long *) * height); - if (!me->pixels) - { + me->pixels = (unsigned long *) malloc(sizeof(unsigned long) * width * height); + if (!me->pixels){ free(me); return NULL; - } - + } + me->rows = (unsigned long **) malloc(sizeof(unsigned long *) * height); + if (!me->rows){ + free(me->pixels); //allocated as me->pixels is not NULL here: see previous check + free(me); + return NULL; + } + unsigned long *row = me->pixels; for (int i=0 ; ipixels) + if (me->pixels){ free(me->pixels); - if (me->rows) + } + if (me->rows){ free(me->rows); + } free(me); } @@ -283,9 +287,10 @@ RgbMap *RgbMapCreate(int width, int height) { RgbMap *me = (RgbMap *)malloc(sizeof(RgbMap)); - if (!me) + if (!me){ return NULL; - + } + /** methods **/ me->setPixel = rSetPixel; me->setPixelRGB = rSetPixelRGB; @@ -297,22 +302,23 @@ RgbMap *RgbMapCreate(int width, int height) /** fields **/ me->width = width; me->height = height; - me->pixels = (RGB *) - malloc(sizeof(RGB) * width * height); - me->rows = (RGB **) - malloc(sizeof(RGB *) * height); - if (!me->pixels) - { + me->pixels = (RGB *) malloc(sizeof(RGB) * width * height); + if (!me->pixels){ free(me); return NULL; - } + } + me->rows = (RGB **) malloc(sizeof(RGB *) * height); + if (!me->rows){ + free(me->pixels); //allocated as me->pixels is not NULL here: see previous check + free(me); + return NULL; + } RGB *row = me->pixels; - for (int i=0 ; irows[i] = row; row += width; - } + } return me; } @@ -376,10 +382,12 @@ static int iWritePPM(IndexedMap *me, char *fileName) static void iDestroy(IndexedMap *me) { - if (me->pixels) + if (me->pixels){ free(me->pixels); - if (me->rows) + } + if (me->rows){ free(me->rows); + } free(me); } @@ -403,31 +411,31 @@ IndexedMap *IndexedMapCreate(int width, int height) /** fields **/ me->width = width; me->height = height; - me->pixels = (unsigned int *) - malloc(sizeof(unsigned int) * width * height); - me->rows = (unsigned int **) - malloc(sizeof(unsigned int *) * height); - if (!me->pixels) - { + me->pixels = (unsigned int *) malloc(sizeof(unsigned int) * width * height); + if (!me->pixels){ free(me); return NULL; - } + } + me->rows = (unsigned int **) malloc(sizeof(unsigned int *) * height); + if (!me->rows){ + free(me->pixels); //allocated as me->pixels is not NULL here: see previous check + free(me); + return NULL; + } unsigned int *row = me->pixels; - for (int i=0 ; irows[i] = row; row += width; - } + } me->nrColors = 0; RGB rgb; rgb.r = rgb.g = rgb.b = 0; - for (int i=0; i<256 ; i++) - { + for (int i=0; i<256 ; i++){ me->clut[i] = rgb; - } + } return me; } -- cgit v1.2.3 From a695510ee8752fee48b98f7b4177115876a0a3a6 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 23 Jan 2013 22:18:32 +0100 Subject: fix Memory leak in bitmap trace (Bug #996695) (bzr r12057) --- src/trace/imagemap-gdk.cpp | 14 ++++++++------ src/trace/imagemap-gdk.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/trace') diff --git a/src/trace/imagemap-gdk.cpp b/src/trace/imagemap-gdk.cpp index e5ff23ad0..06f355de7 100644 --- a/src/trace/imagemap-gdk.cpp +++ b/src/trace/imagemap-gdk.cpp @@ -58,7 +58,7 @@ GdkPixbuf *grayMapToGdkPixbuf(GrayMap *grayMap) GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, 0, 8, grayMap->width, grayMap->height, - rowstride, NULL, NULL); + rowstride, (GdkPixbufDestroyNotify)g_free, NULL); //### Fill in the odd cells with RGB values int x,y; @@ -122,7 +122,7 @@ PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf) return ppMap; } -GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) +/*GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) { if (!ppMap) return NULL; @@ -137,7 +137,7 @@ GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, 0, 8, ppMap->width, ppMap->height, - rowstride, NULL, NULL); + rowstride, NULL, NULL); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? //### Fill in the cells with RGB values int x,y; @@ -158,7 +158,7 @@ GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) return buf; } - +*/ /*######################################################################### @@ -203,6 +203,7 @@ RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf) return rgbMap; } +/* GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) { if (!rgbMap) @@ -218,7 +219,7 @@ GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, 0, 8, rgbMap->width, rgbMap->height, - rowstride, NULL, NULL); + rowstride, NULL, NULL); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? //### Fill in the cells with RGB values int x,y; @@ -239,6 +240,7 @@ GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) return buf; } +*/ /*######################################################################### ## I N D E X E D M A P @@ -260,7 +262,7 @@ GdkPixbuf *indexedMapToGdkPixbuf(IndexedMap *iMap) GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, 0, 8, iMap->width, iMap->height, - rowstride, NULL, NULL); + rowstride, (GdkPixbufDestroyNotify)g_free, NULL); //### Fill in the cells with RGB values int x,y; diff --git a/src/trace/imagemap-gdk.h b/src/trace/imagemap-gdk.h index d04a84d8e..3b4631f50 100644 --- a/src/trace/imagemap-gdk.h +++ b/src/trace/imagemap-gdk.h @@ -29,11 +29,11 @@ GdkPixbuf *grayMapToGdkPixbuf(GrayMap *grayMap); PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf); -GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap); +//GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap); RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf); -GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap); +//GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap); GdkPixbuf *indexedMapToGdkPixbuf(IndexedMap *iMap); -- cgit v1.2.3 From 1d66df63a0263476b774fe9fe4854afea60489f2 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 30 Jan 2013 18:24:39 +0100 Subject: removing some more unused functions (bzr r12076) --- src/trace/filterset.cpp | 35 ---------------------- src/trace/filterset.h | 6 ---- src/trace/imagemap-gdk.cpp | 75 ---------------------------------------------- src/trace/imagemap-gdk.h | 8 ----- 4 files changed, 124 deletions(-) (limited to 'src/trace') diff --git a/src/trace/filterset.cpp b/src/trace/filterset.cpp index 908985225..f6c025956 100644 --- a/src/trace/filterset.cpp +++ b/src/trace/filterset.cpp @@ -365,41 +365,6 @@ grayMapCanny(GrayMap *gm, double lowThreshold, double highThreshold) - - - - -/** - * - */ -GdkPixbuf * -gdkCanny(GdkPixbuf *img, double lowThreshold, double highThreshold) -{ - if (!img) - return NULL; - - - GrayMap *grayMap = gdkPixbufToGrayMap(img); - if (!grayMap) - return NULL; - - /*grayMap->writePPM(grayMap, "gbefore.ppm");*/ - - GrayMap *cannyGm = grayMapCanny(grayMap,lowThreshold, highThreshold); - - grayMap->destroy(grayMap); - - if (!cannyGm) - return NULL; - - /*grayMap->writePPM(grayMap, "gafter.ppm");*/ - - GdkPixbuf *newImg = grayMapToGdkPixbuf(cannyGm); - - - return newImg; -} - /*######################################################################### ### Q U A N T I Z A T I O N #########################################################################*/ diff --git a/src/trace/filterset.h b/src/trace/filterset.h index eeafc079f..820d225c3 100644 --- a/src/trace/filterset.h +++ b/src/trace/filterset.h @@ -37,12 +37,6 @@ RgbMap *rgbMapGaussian(RgbMap *rgbmap); GrayMap *grayMapCanny(GrayMap *gmap, double lowThreshold, double highThreshold); -/** - * - */ -GdkPixbuf *gdkCanny(GdkPixbuf *img, - double lowThreshold, double highThreshold); - /** * */ diff --git a/src/trace/imagemap-gdk.cpp b/src/trace/imagemap-gdk.cpp index 06f355de7..7c7139002 100644 --- a/src/trace/imagemap-gdk.cpp +++ b/src/trace/imagemap-gdk.cpp @@ -122,44 +122,6 @@ PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf) return ppMap; } -/*GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) -{ - if (!ppMap) - return NULL; - - guchar *pixdata = (guchar *) - malloc(sizeof(guchar) * ppMap->width * ppMap->height * 3); - if (!pixdata) - return NULL; - - int n_channels = 3; - int rowstride = ppMap->width * 3; - - GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, - 0, 8, ppMap->width, ppMap->height, - rowstride, NULL, NULL); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? - - //### Fill in the cells with RGB values - int x,y; - int row = 0; - for (y=0 ; yheight ; y++) - { - guchar *p = pixdata + row; - for (x=0 ; xwidth ; x++) - { - unsigned long rgb = ppMap->getPixel(ppMap, x, y); - p[0] = (rgb >> 16) & 0xff; - p[1] = (rgb >> 8) & 0xff; - p[2] = (rgb ) & 0xff; - p += n_channels; - } - row += rowstride; - } - - return buf; -} -*/ - /*######################################################################### ## R G B M A P @@ -203,44 +165,7 @@ RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf) return rgbMap; } -/* -GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) -{ - if (!rgbMap) - return NULL; - - guchar *pixdata = (guchar *) - malloc(sizeof(guchar) * rgbMap->width * rgbMap->height * 3); - if (!pixdata) - return NULL; - - int n_channels = 3; - int rowstride = rgbMap->width * 3; - - GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, - 0, 8, rgbMap->width, rgbMap->height, - rowstride, NULL, NULL); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? - - //### Fill in the cells with RGB values - int x,y; - int row = 0; - for (y=0 ; yheight ; y++) - { - guchar *p = pixdata + row; - for (x=0 ; xwidth ; x++) - { - RGB rgb = rgbMap->getPixel(rgbMap, x, y); - p[0] = rgb.r & 0xff; - p[1] = rgb.g & 0xff; - p[2] = rgb.b & 0xff; - p += n_channels; - } - row += rowstride; - } - return buf; -} -*/ /*######################################################################### ## I N D E X E D M A P diff --git a/src/trace/imagemap-gdk.h b/src/trace/imagemap-gdk.h index 3b4631f50..63281658a 100644 --- a/src/trace/imagemap-gdk.h +++ b/src/trace/imagemap-gdk.h @@ -24,17 +24,9 @@ extern "C" { #endif GrayMap *gdkPixbufToGrayMap(GdkPixbuf *buf); - GdkPixbuf *grayMapToGdkPixbuf(GrayMap *grayMap); - PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf); - -//GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap); - RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf); - -//GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap); - GdkPixbuf *indexedMapToGdkPixbuf(IndexedMap *iMap); -- cgit v1.2.3