From 37ce1c1bf518725405e919797eb43ee82d753f31 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Thu, 2 Oct 2025 09:52:07 +0200 Subject: [PATCH] change stat to heap --- src/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 681aa0d..6a6d2c8 100644 --- a/src/main.c +++ b/src/main.c @@ -9,7 +9,7 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) { glob_t* files = malloc(sizeof(glob_t)); - struct stat statbuf; + struct stat* statbuf = malloc(sizeof(struct stat)); char* pattern = NULL; char* input_filename = NULL; char* output_filename = NULL; @@ -25,14 +25,14 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) glob(pattern, 0, NULL, files); for (int i = 0; i < files->gl_pathc; i++) { - stat(files->gl_pathv[i], &statbuf); + stat(files->gl_pathv[i], statbuf); renamefunc(files->gl_pathv[i], output_filename); if (strcmp(files->gl_pathv[i], output_filename) != 0) { printf("%s -> %s\n", files->gl_pathv[i], output_filename); rename(files->gl_pathv[i], output_filename); } - if (S_ISDIR(statbuf.st_mode)) { + if (S_ISDIR(statbuf->st_mode)) { escape_str(output_filename, input_filename); rename_files(input_filename, renamefunc); } @@ -43,6 +43,8 @@ void rename_files(const char* dir_path, rename_func_ptr renamefunc) globfree(files); files = NULL; + free(statbuf); + statbuf = NULL; free(pattern); pattern = NULL; free(input_filename); -- 2.47.3