DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: http://www.fltk.org/str.php?L2425
Version: 2.0-current
Whilst trying to fix a couple of things with fluid2-shared I ran valgrind
over the top to check memory usage.
The attached patch only recovers about 2kb, but it also deals with a few
cases where realloc fails.
This really only recovers the obvious leaks, but as I get more of a chance
to attack this with a fine-toothed comb, I might have slightly better
results.
I'll slowly add to bits either here or in other opened STRs to try to
recover all the memory that's leaked, amongst other things.
Link: http://www.fltk.org/str.php?L2425
Version: 2.0-current
Index: fluid/WidgetType.cxx
===================================================================
--- fluid/WidgetType.cxx (revision 7707)
+++ fluid/WidgetType.cxx (working copy)
@@ -302,7 +302,11 @@
i->static_value(current_widget->label());
if (strlen(i->value()) >= oldlabellen) {
oldlabellen = strlen(i->value())+128;
- oldlabel = (char*)realloc(oldlabel,oldlabellen);
+ char* temp = (char*)realloc(oldlabel, oldlabellen);
+ if (temp)
+ // I'm going to assume that if we're *not* in here
+ // something bad has happened, so don't modify the label;
+ oldlabel=temp;
}
strcpy(oldlabel,i->value());
} else {
@@ -324,7 +328,10 @@
i->static_value(current_widget->tooltip());
if (strlen(i->value()) >= oldtooltiplen) {
oldtooltiplen = strlen(i->value())+128;
- oldtooltip = (char*)realloc(oldtooltip,oldtooltiplen);
+ char* temp = (char*)realloc(oldtooltip,oldtooltiplen);
+ if (temp)
+ // same theory as lines 307/308 above
+ oldtooltip=temp;
}
strcpy(oldtooltip,i->value());
} else {
Index: fluid/Fluid_Image.cxx
===================================================================
--- fluid/Fluid_Image.cxx (revision 7707)
+++ fluid/Fluid_Image.cxx (working copy)
@@ -50,14 +50,35 @@
do {
c*=2;
cc+=c;
- if(d)
- d=(uchar *) realloc(d, cc);
- else
- d=(uchar *) malloc(cc);
+ if (d){
+ uchar* temp = (uchar*)realloc(d, cc);
+ if (!temp) {
+ free(d);
+ fclose(fd);
+ return 0;
+ }
+ d = temp;
+ }
+ else {
+ d = (uchar *) malloc(cc);
+ if (!d) {
+ fclose(fd);
+ return 0;
+ }
+ }
r=fread(d+cc-c, 1, c, fd);
size+=r;
} while(r==c);
- if(size!=cc) d=(uchar *) realloc(d, size?size:1);
+ if(size!=cc) {
+ uchar* temp = (uchar *) realloc(d, size?size:1);
+ if (!temp) {
+ free(d);
+ fclose(fd);
+ return 0;
+ }
+ d = temp;
+ }
+ fclose(fd);
return d;
}
@@ -241,7 +262,10 @@
// read the data:
i = 0;
for (;i<n;) {
- if (!fgets(buffer,1024,f)) return;
+ if (!fgets(buffer,1024,f)) {
+ delete[] data;
+ return;
+ }
const char *a = buffer;
while (*a && i<n) {
int t;
@@ -250,6 +274,7 @@
}
}
p = new fltk::xbmImage(data,wh[0],wh[1]);
+ delete [] data;
}
bitmap_image::~bitmap_image() {
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs