How to realloc some memory allocated using calloc?
问题 I've allocated a string with the calloc function: //string1 and string2 previously declared char *stringClone = calloc(strlen(string1) + 1, sizeof(char)); Now I want to do the same thing on stringClone with a different string. Doing: stringClone = calloc(strlen(string2) + 1, sizeof(char)); I'm gonna have some memory leak, right? How should I use the realloc in this case? 回答1: You can use realloc() to reallocate memory allocated by malloc() , calloc() , realloc() , aligned_alloc() or strdup()