Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory overflow #81

Merged
merged 4 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static char *CacheSystem_calc_dir(const char *url)
fprintf(stderr, "CacheSystem_calc_dir(): mkdir(): %s\n",
strerror(errno));
}
free(fn);
free(cache_dir_root);
curl_free(escaped_url);
curl_easy_cleanup(c);
Expand Down Expand Up @@ -115,10 +116,9 @@ void CacheSystem_init(const char *path, int url_supplied)
"CacheSystem_init(): opendir(): %s\n", strerror(errno));
exit_failure();
}

closedir(dir);
META_DIR = path_append(path, "meta/");
DATA_DIR = path_append(path, "data/");

/* Check if directories exist, if not, create them */
if (mkdir(META_DIR, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
&& (errno != EEXIST)) {
Expand Down Expand Up @@ -463,6 +463,8 @@ int CacheDir_create(const char *dirn)
if (i && (errno != EEXIST)) {
fprintf(stderr, "CacheDir_create(): mkdir(): %s\n", strerror(errno));
}
free(datadirn);
free(metadirn);
return -i;
}

Expand Down Expand Up @@ -983,7 +985,7 @@ long Cache_read(Cache *cf, char * const output_buf, const off_t len,
off_t dl_offset = (offset_start + len) / cf->blksz * cf->blksz;

/* ------------------ Check if the segment already exists ---------------*/
if (Seg_exist(cf, dl_offset)) {
if (dl_offset == 0 || Seg_exist(cf, dl_offset)) {
send = Data_read(cf, (uint8_t *) output_buf, len, offset_start);
goto bgdl;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ LinkTable *LinkSystem_init(const char *raw_url)
ROOT_LINK_TBL = sonic_LinkTable_new_id3(0, "0");
}
}
free(url);
return ROOT_LINK_TBL;
}

Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void parse_config_file(char ***argv, int *argc)
}
}
}
free(full_path);
}

static int
Expand Down