hello,
is the above code memory OK or the continuous allocation of malloc will lead to a memory leak problem (imagine i have a big loop of reading strings)? in other words is the use of malloc correct or do i need to use realloc? as i think the only difference between the two is that malloc is destructive without copying the previous contents while realloc is also destructive but copies the old contents if necessaryCode:char *str; str = (char *) malloc (sizeof (char) * strlen("hello")); strcpy(str, "hello"); str = (char *) malloc (sizeof (char) * strlen("bye bye")); strcpy(str, "bye bye"); g_free(str);
cheers