Strange problem with new in a DLL

A

Al Newton

I created a DLL that reads a pointer to a vector created in a
console-mode test app as:
vector<LineItem*>* pLineItems = new vector<LineItem*>;
Everything seems to work fine (except for memory leaks) if I don't do
a delete in the test app. But if I do, I get an exception on the test
app's return 0 statement.

BoundsChecker tells me that I am attempting to free memory in the DLL
that was allocated in the test routine. I don't understand this
because the DLL does not contain even a single delete.

Can someone shed some light on this behavior? Thanks ... Al
 
V

Victor Bazarov

Al Newton said:
I created a DLL that reads a pointer to a vector created in a
console-mode test app as:
vector<LineItem*>* pLineItems = new vector<LineItem*>;
Everything seems to work fine (except for memory leaks) if I don't do
a delete in the test app. But if I do, I get an exception on the test
app's return 0 statement.

BoundsChecker tells me that I am attempting to free memory in the DLL
that was allocated in the test routine. I don't understand this
because the DLL does not contain even a single delete.

Can someone shed some light on this behavior? Thanks ... Al

You probably need to ask in a newsgroup where DLLs are on topic.
As far as C++ is concerned, if you allocate memory in a program,
you should be able to free it in the same program.

<offtopic> You might want to make sure that both the App and the
DLL use the run-time library as a DLL too</offtopic>

Victor
 
G

Gianni Mariani

Al said:
I created a DLL that reads a pointer to a vector created in a
console-mode test app as:
vector<LineItem*>* pLineItems = new vector<LineItem*>;
Everything seems to work fine (except for memory leaks) if I don't do
a delete in the test app. But if I do, I get an exception on the test
app's return 0 statement.

BoundsChecker tells me that I am attempting to free memory in the DLL
that was allocated in the test routine. I don't understand this
because the DLL does not contain even a single delete.

Can someone shed some light on this behavior? Thanks ... Al

I don't know how bounds checker works but it's likely that it is not
reporting correctly.

The problem is that the new() operator is inlined and bounds checker
probably only knows about malloc and free. Hence what bounds checker is
reporting is totally bogus.

How to fix this in win32 apps is still a mystery to me, however with gcc
there are ways to make it so that checkers can work correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top