![]() The first string will eventually end up in the array but the second string is leaked. Here, each substr call allocates a string. For example: array = concat(substr(word, 0, i), substr(word, i+1, word_len-(i+1))) ![]() All of your functions allocate space for new strings, but you never free your temporary strings. Memory leaksĪfter reading your concatenation code again, I see a lot of memory leaks. At first I couldn't understand why you were taking the maximum of an array and an int, until I realized that you wrote a function called max() that didn't just return the maximum of two values. Res = checked_realloc(res, sizeof(char *) * res_max) Int deletion(char *word, char **array, int start_idx) ![]() Static void append(char *dst, int *dstLen, const char *src, int srcBegin, * srcBegin Starting index in the source string to copy from. * be updated with the new length after appending. * dstLen Current length of the destination string. * Takes a part of the source string and appends it to the destination string. Here is a rewrite of your concatenation functions, which doubled the speed of your program: static void *checked_malloc(int len)
0 Comments
Leave a Reply. |