Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7957 Discussions

Need help with ASSERTE _CrtIsValidHeapPointer (pUserData)

jim_cox
Beginner
477 Views
Hello All

I'm moving some old msC++ code to Intel

With Intel, the porgram generates an _ASSERTE _CrtIsValidHeapPointer (pUserData) when running



The code in question is calling free(value)

Where value is locally defined as char *value

Presumably this implies that value has been created on the stack



So my questions are

a: should free be being called at all ?

and b: if so is there a compiler setting that will allow the Intel build to run as before?



Thankx for your help

Jim

=mjc=
.

0 Kudos
1 Solution
Dale_S_Intel
Employee
477 Views
Well, unless I'm missing something, the issue is not how value has been declared (as a char *) but what has been assigned to it. If it has been assigned using some sort of malloc(), then it there should be a free() of it, but if it has been assigned some other way, or if free() has already been called on that location somewhere else (possibly in another function) then I would expect it to be problematic. For example, if you said

char *value;
value = "Hello World";

then you would not want to call free(value). But if you said

vaule = (char *)malloc(strlen("Hello World"));

then you should call free(value) at some point.

Is that what you're asking?

Thanks!
Dale

View solution in original post

0 Kudos
2 Replies
Dale_S_Intel
Employee
478 Views
Well, unless I'm missing something, the issue is not how value has been declared (as a char *) but what has been assigned to it. If it has been assigned using some sort of malloc(), then it there should be a free() of it, but if it has been assigned some other way, or if free() has already been called on that location somewhere else (possibly in another function) then I would expect it to be problematic. For example, if you said

char *value;
value = "Hello World";

then you would not want to call free(value). But if you said

vaule = (char *)malloc(strlen("Hello World"));

then you should call free(value) at some point.

Is that what you're asking?

Thanks!
Dale
0 Kudos
jim_cox
Beginner
477 Views
Thankx Dale

You have confirmed my suspicions

There is no malloc - therefore the free is bad.

And I suspect this was not being caught by the old compiler

I comment out the statements (there were many of them) and the Assert goes away :)

Thankx again for your help

Cheers

Jim

=mjc=
.
0 Kudos
Reply