c freeing char pointer not working after first time
I am trying to free a char pointer which was allocated by the function copyCharNumber. The first time the free call in the function works fine. The second time it doesn´t work any more and Visual Studio throws an error. I don't get it why there is an error the second time. The second time calling free on the char pointer returned by the copyCharNumber anywhere in the code always throws an error. Code: char *copyCharNumber(char *oldNumber, char *newDigit, int newLen) { char *newNumber = malloc(newLen * sizeof(char) + 1); if (oldNumber != NULL) { strcpy(newNumber, oldNumber); free(oldNumber); }
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.