C free error

December 25, 2010 at 16:30:38
Specs: Windows 7
im having troubles using the free comand, i know the problem is in the malloc definition, cause the error im getting releated to heap
can you explain to me what im doing wrong?


See More: C free error

Report •

December 26, 2010 at 14:35:00
Is this C or C++? If it's straight C, casting from void* is implicit. If it's C++, you should use new, which will throw on a problem. On either platform, you should be using size_t, not int.

That said, strlen() returns the size of the string, minus the terminating null. You need to account for this null in your allocations.

if (region_root->region->name = malloc((strlen(name) + 1) * sizeof(char)))

How To Ask Questions The Smart Way

Report •

December 27, 2010 at 14:50:59
yea the +1 made it ty its c btw

Report •

Related Solutions

Ask Question