Memory leak in carz.pp (rob_name)
| Version | 0.73b |
| Solved in | 0.73c |
| File | car.h + carz.cpp + movie.cpp + driver.cpp |
| Owner | Marc Gueury |
| Platform | ALL |
| Impact on cars | NONE |
| Impact on portability | NONE |
Description:
Problem of memory allocation of the names in carz.cpp.
Variable rob_name is allocated per car and never removed.
In car.h
[...]
struct car_ID { // This structure make
one car different from another
robot* rob_ptr;
// pointer to the robot "driver" function;
colors paint_job;
// the nose and tail colors
char* bitmap_name; // name
of the bitmap to use to display the car
char* rob_name;
// pointer to the first character of the name string
};
[...]
In carz.cpp
[...]
void get_names(void)
{
<snip>
drivers[i].rob_name = new char[33];
[...]
In movie.cpp
[...]
VOID ReplayInit( fstream& in, int *car_count, car_ID *drivers )
{
<Snip>
ThisCar->rob_name = (char *)malloc( (strlen(buf)+1) * sizeof(char)
);
strcpy( ThisCar->rob_name, buf );
[...]
Solution
Change of the definition of rob_name. Both allocations are removed.
In car.h
[...]
char rob_name[33];
// pointer to the first character of the name string
};
[...]
In driver.cpp
{ Indretti, {oGREEN, oRED},
"bitmap/car12", (char *)0 }
->
{ Indretti, {oGREEN, oRED},
"bitmap/car12", 0 }