Trying to find the bug in tower.cxx (that crashes fgfs quite frequently
for me!), I'm playing with valgrind again. Until I'm in the ATC subsystem
there will be some other bugs and nitpicking along the way.
valgrind doesn't like that imgage->tmp is once allocated with new and
once with new[], sometimes with malloc() (via map), and sometimes freed
with delete (not delete[]!) and sometimes with free(). With simple types
such as GLubyte this shouldn't really make a difference, but anyway.
Also, I promised that I'd send patches for "if (foo) delete foo;" as
I'm making other changes to concerned files. texture.cxx is one with a
few occurrences thereof. (Remember: C++ explicitly allows to delete
null-pointers, so this check is redundant, and hence not tolerated in
other projects, such as KDE. Doesn't have to impress us, of course. :-)
Also, fixes 4 signed/unsigned warnings (gcc 3.3.4)
SGTexture::~SGTexture()
{
SGTexture::~SGTexture()
{
- if ( texture_data ) {
- delete texture_data;
- }
if ( texture_id != 0 ) {
free_id();
if ( texture_id != 0 ) {
free_id();
SGTexture::ImageRec *image;
int y;
SGTexture::ImageRec *image;
int y;
- if (texture_data)
- delete texture_data;
image = ImageOpen(name);
if(!image) {
image = ImageOpen(name);
if(!image) {
SGTexture::ImageRec *image;
int y;
SGTexture::ImageRec *image;
int y;
- if (texture_data)
- delete texture_data;
image = ImageOpen(name);
if(!image) {
image = ImageOpen(name);
if(!image) {
bbuf = new GLubyte[ image->xsize ];
abuf = new GLubyte[ image->xsize ];
if(!texture_data || !rbuf || !gbuf || !bbuf || !abuf) {
bbuf = new GLubyte[ image->xsize ];
abuf = new GLubyte[ image->xsize ];
if(!texture_data || !rbuf || !gbuf || !bbuf || !abuf) {
- delete texture_data;
- delete rbuf;
- delete gbuf;
- delete bbuf;
- delete abuf;
+ delete[] texture_data;
+ delete[] rbuf;
+ delete[] gbuf;
+ delete[] bbuf;
+ delete[] abuf;
errstr = OUT_OF_MEMORY;
return;
}
errstr = OUT_OF_MEMORY;
return;
}
- delete rbuf;
- delete gbuf;
- delete bbuf;
- delete abuf;
+ delete[] rbuf;
+ delete[] gbuf;
+ delete[] bbuf;
+ delete[] abuf;
SGTexture::ImageRec *image;
int y;
SGTexture::ImageRec *image;
int y;
- if (texture_data)
- delete texture_data;
image = ImageOpen(name);
if(!image) {
image = ImageOpen(name);
if(!image) {
bbuf = new GLubyte[ image->xsize ];
abuf = new GLubyte[ image->xsize ];
if(!texture_data || !rbuf || !gbuf || !bbuf || !abuf) {
bbuf = new GLubyte[ image->xsize ];
abuf = new GLubyte[ image->xsize ];
if(!texture_data || !rbuf || !gbuf || !bbuf || !abuf) {
- delete texture_data;
- delete rbuf;
- delete gbuf;
- delete bbuf;
- delete abuf;
+ delete[] texture_data;
+ delete[] rbuf;
+ delete[] gbuf;
+ delete[] bbuf;
+ delete[] abuf;
errstr = OUT_OF_MEMORY;
return;
}
errstr = OUT_OF_MEMORY;
return;
}
- delete rbuf;
- delete gbuf;
- delete bbuf;
- delete abuf;
+ delete[] rbuf;
+ delete[] gbuf;
+ delete[] bbuf;
+ delete[] abuf;
SGTexture::ImageRec *image;
int y;
SGTexture::ImageRec *image;
int y;
- if (texture_data)
- delete texture_data;
image = RawImageOpen(name);
image = RawImageOpen(name);
SGTexture::ImageRec *image;
int xy;
SGTexture::ImageRec *image;
int xy;
- if (texture_data)
- delete texture_data;
//it wouldn't make sense to write a new function ...
image = RawImageOpen(name);
//it wouldn't make sense to write a new function ...
image = RawImageOpen(name);
SGTexture::ImageClose(SGTexture::ImageRec *image) {
if (image->file) gzclose(image->file);
if (file) fclose(file);
SGTexture::ImageClose(SGTexture::ImageRec *image) {
if (image->file) gzclose(image->file);
if (file) fclose(file);
//just allocate a pseudo value as I'm too lazy to change ImageClose()...
//just allocate a pseudo value as I'm too lazy to change ImageClose()...
- image->tmp = new GLubyte;
+ image->tmp = new GLubyte[1];
if (image->tmp == 0) {
errstr = OUT_OF_MEMORY;
if (image->tmp == 0) {
errstr = OUT_OF_MEMORY;
return;
int colors = (num_colors == 3) ? 1 : 2;
return;
int colors = (num_colors == 3) ? 1 : 2;
- GLubyte *map = (GLubyte *)malloc (texture_width * texture_height * colors);
+ GLubyte *map = new GLubyte[ texture_width * texture_height * colors ];
for (int y=0; y<texture_height; y++)
for (int x=0; x<texture_width; x++)
for (int y=0; y<texture_height; y++)
for (int x=0; x<texture_width; x++)
texture_data = map;
num_colors = colors;
}
texture_data = map;
num_colors = colors;
}
SGTexture::make_maxcolorwindow() {
GLubyte minmaxc[2] = {255, 0};
SGTexture::make_maxcolorwindow() {
GLubyte minmaxc[2] = {255, 0};
- unsigned int pos = 0;
- unsigned int max = num_colors;
+ int pos = 0;
+ int max = num_colors;
if (num_colors == 2) max = 1;
if (num_colors == 4) max = 3;
while (pos < texture_width * texture_height * num_colors) {
if (num_colors == 2) max = 1;
if (num_colors == 4) max = 3;
while (pos < texture_width * texture_height * num_colors) {
int colors = (num_colors == 1) ? 3 : 4;
bool alpha = (colors > 3);
int tsize = texture_width * texture_height * colors;
int colors = (num_colors == 1) ? 3 : 4;
bool alpha = (colors > 3);
int tsize = texture_width * texture_height * colors;
- GLubyte *map = (GLubyte *)malloc (tsize);
+ GLubyte *map = new GLubyte[ tsize ];
int mpos = 0, dpos = 0;
for (int y=0; y<texture_height; y++) {
int mpos = 0, dpos = 0;
for (int y=0; y<texture_height; y++) {
texture_data = map;
num_colors = colors;
}
texture_data = map;
num_colors = colors;
}
make_grayscale(contrast);
int colors = (num_colors == 1) ? 1 : 2;
make_grayscale(contrast);
int colors = (num_colors == 1) ? 1 : 2;
- GLubyte *map = (GLubyte *)malloc (texture_width * texture_height * colors);
+ GLubyte *map = new GLubyte[ texture_width * texture_height * colors ];
for (int y=0; y<texture_height; y++)
for (int x=0; x<texture_width; x++)
for (int y=0; y<texture_height; y++)
for (int x=0; x<texture_width; x++)
map[mpos+1] = texture_data[dpos+1];
}
map[mpos+1] = texture_data[dpos+1];
}
texture_data = map;
num_colors = colors;
}
texture_data = map;
num_colors = colors;
}