Hi All,

I am facing problems with free() API of ANSI.
I am using Visual Studio 2005. I am using 2 char pointers. If i copy from one to another and after if i try to free source pointer, it is giving exception. How to debug this problem?

Please help me anybody.

9 Years
Discussion Span
Last Post by jephthah

If you're seeing a runtime error inside free, it means you corrupted the memory. Verify that you're allocating enough memory, then make sure you don't access that memory out of bounds. There's nothing wrong with the free function itself.


for one thing, you dont "free" a pointer. you free previously allocated memory space.

that you're talking about freeing a pointer, makes me suspect you didn't allocate the memory in the first place.

of course it's all speculation at this point, since you haven't posted any code for us to look at.


>for one thing, you dont "free" a pointer.
You're correct, pedantically speaking, but programmers typically don't speak pedantically unless they're trying to avoid annoying nitpickers. It's perfectly reasonable to say you're freeing a pointer, and the statement doesn't indicate either lack of understanding or the presence of bugs.

>makes me suspect you didn't allocate the memory in the first place.
That's one possibility, but the way you reached the conclusion is nonsensical.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.