By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Strange problem with new in a DLL

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Al Newton" <al*******@hotmail.com> wrote...
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
Jul 19 '05 #2

P: n/a
Al Newton wrote:
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.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.