238 char* prefix = calloc(prefix_end + 3, sizeof(char));
239 getPrefix(wildcard_groups, prefix, i, prefix_end);
240
241 char* start = &wildcard_groups.arr[i].wildcard_arg[prefix_end];
242 bool is_dotfile = start[0] == '.' ? true : false;
243
244 int end_index = calculateEndIndex(wildcard_groups, j, i);
245 char* end = &wildcard_groups.arr[i].wildcard_arg[end_index];
246
247 char* regex = calloc(((end - start) * 2) + 3, sizeof(char));
248 regex = createRegex(regex, start, end);
249 regex_t re;
250 if (regcomp(&re, regex, REG_EXTENDED) != 0) {
251 perror("regex");
252 }
253
254 removeSlice(&wildcard_groups.arr[i].wildcard_arg, 0, end_index);
255 int concat_index = calculateConcatIndex(prefix);
256
257 DIR* current_dir = opendir(prefix);
258 if (current_dir == NULL) {
259 // when wrong dir make wildcard empty so that foundAllWildcards is false
260 fprintf(stderr, "psh: couldn't open directory: %s\n", prefix);
261 strcpy(wildcard_groups.arr[0].wildcard_arg, "");
262 return wildcard_groups;
263 }
At main.c:262, it leaks prefix and regex, and maybe re, depending on if regcomp() succeeded. Also, if regcomp() fails, it prints a message, but then proceeds as if it had succeeded which I suspect is not the correct behavior.
Found this via clang's scan build.
Attached patch allows invoking clang scan build via "make scan-build"
allow-invoking-clang-scan-build-from-makefile.txt
At main.c:262, it leaks prefix and regex, and maybe re, depending on if regcomp() succeeded. Also, if regcomp() fails, it prints a message, but then proceeds as if it had succeeded which I suspect is not the correct behavior.
Found this via clang's scan build.
Attached patch allows invoking clang scan build via "make scan-build"
allow-invoking-clang-scan-build-from-makefile.txt