Skip to content

Commit cb578f4

Browse files
committed
fix potential memory leak identified by valgrind?
1 parent 472186a commit cb578f4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

FuseRedSea.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ static int fuse_rs_create(const char* path, mode_t perms, struct fuse_file_info*
739739
char* last_slash = strrchr(path, '/');
740740

741741
int dirlen = last_slash - path;
742-
char* directory_path = malloc(dirlen);
742+
char* directory_path = calloc(dirlen+1,1);
743743
strncpy(directory_path, path, dirlen);
744744

745745
fprintf(stderr, "%s\n", directory_path);
@@ -768,7 +768,7 @@ static int fuse_rs_create(const char* path, mode_t perms, struct fuse_file_info*
768768
unsigned long long int size = 0;
769769
unsigned long long int block = free_space_pointer;
770770
free_space_pointer++;
771-
unsigned char* name = calloc(38, 1);
771+
unsigned char* name = calloc(38,1);
772772
strcpy(name, last_slash+1);
773773

774774
// if compressed
@@ -824,7 +824,7 @@ static int fuse_rs_mkdir(const char* path, mode_t perms) {
824824
char* last_slash = strrchr(path, '/');
825825

826826
int parlen = last_slash - path;
827-
char* parent_path = malloc(parlen);
827+
char* parent_path = calloc(parlen+1, 1);
828828
strncpy(parent_path, path, parlen);
829829

830830
unsigned long long int pdid = directory_position(parent_path);

0 commit comments

Comments
 (0)