Skip to content

Commit

Permalink
fix potential memory leak identified by valgrind?
Browse files Browse the repository at this point in the history
  • Loading branch information
ecpre committed Mar 4, 2023
1 parent 472186a commit cb578f4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions FuseRedSea.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ static int fuse_rs_create(const char* path, mode_t perms, struct fuse_file_info*
char* last_slash = strrchr(path, '/');

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

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

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

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

unsigned long long int pdid = directory_position(parent_path);
Expand Down

0 comments on commit cb578f4

Please sign in to comment.