its seems it was all about memory leak, I have used the function _CrtDumpMemoryLeaks();
before and after malloc
function.
before the malloc I get nothing, and when _CrtDumpMemoryLeaks();
runs after the malloc I get the following:
Detected memory leaks!
Dumping objects ->
c:\users\omers66\documents\visual studio 2013\projects\assigment4\assigment4 \assignment4.c(150) : {66} normal block at 0x00F57338, 20 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
The program '[7588] assigment4.exe' has exited with code 0 (0x0).
I guess it means I have an issue with line 150? But I can't see anything wrong, here is the code in that section:
struct Unit* add_unit(struct Unit* tree, int base, int newId, char*name)
{
_CrtDumpMemoryLeaks();
struct UnitList* tempUnitList;
struct Unit* temp;
struct Unit* returnValue = NULL;
char* helpName;
if (tree == NULL)
{
temp = ((struct Unit*)(malloc(sizeof(struct Unit)))); (line 150)
_CrtDumpMemoryLeaks();
can you see anything wrong?
well, eventually It was all an issue with not giving a string enough space with malloc, I forgot to add an extra byte for the '\0' because I used sizeof according to specific string