C
Chameleon
--------------------------------
class A {
int data[1000];
public:
A() { throw; }
};
int main(int, char**) {
try {
A *a = new A;
} catch(...) {}
}
--------------------------------
In code above we have a class which throws in c'tor. Object *a never
created, so d'tor of A never runs.
sizeof(A) is 1000 * sizeof(int), so with new, a block of (not always)
4000 bytes allocated in memory but pointer to that block, never stored
in 'a'. So 'delete a;' is not working.
The question is:
We have a memory leak here?
If yes, how we can fix it?
Thanks
class A {
int data[1000];
public:
A() { throw; }
};
int main(int, char**) {
try {
A *a = new A;
} catch(...) {}
}
--------------------------------
In code above we have a class which throws in c'tor. Object *a never
created, so d'tor of A never runs.
sizeof(A) is 1000 * sizeof(int), so with new, a block of (not always)
4000 bytes allocated in memory but pointer to that block, never stored
in 'a'. So 'delete a;' is not working.
The question is:
We have a memory leak here?
If yes, how we can fix it?
Thanks