Фикс памяти в get_default_filepath

parent 65a62362
......@@ -8,7 +8,7 @@
void usage();
void die(const char *);
char *get_default_filepath(char *);
char *get_default_filepath(char *, char *);
void download_file(char *url, char *filepath, CURL *curl);
int file_exists(const char *filename);
......@@ -26,13 +26,13 @@ main(int argc, char** argv)
char *url_file_path = NULL;
char *filepaths_file_path = NULL;
char *place_holder = NULL; // for get_default_filepath func
//get args
if(argc == 1)
usage();
else if(argc == 2){
url = argv[1];
filepath = get_default_filepath(url);
filepath = get_default_filepath(url, place_holder);
}else{
for(int i = 1; i < argc; i++)
if(!strcmp(argv[i], "-f"))
......@@ -74,7 +74,6 @@ main(int argc, char** argv)
size_t url_len = 0;
size_t filepath_len = 0;
switch(download_type){
case URL_ONLY:
download_file(url, filepath, curl);
......@@ -91,9 +90,9 @@ main(int argc, char** argv)
if (curr_url[strlen(curr_url) - 1] == '\n')
curr_url[strlen(curr_url) - 1] = '\0';
download_file(curr_url, get_default_filepath(curr_url), curl);
download_file(curr_url, get_default_filepath(curr_url, place_holder), curl);
}
free(place_holder);
free(curr_url);
fclose(url_file);
break;
......@@ -109,7 +108,7 @@ main(int argc, char** argv)
while(getline(&curr_url, &filepath_len, url_file) != -1){
if(getline(&curr_filepath, &url_len, filepaths_file) == -1)
curr_filepath = get_default_filepath(curr_url);
curr_filepath = get_default_filepath(curr_url, place_holder);
if (curr_filepath[strlen(curr_filepath) - 1] == '\n')
curr_filepath[strlen(curr_filepath) - 1] = '\0';
......@@ -118,10 +117,10 @@ main(int argc, char** argv)
download_file(curr_url, curr_filepath, curl);
}
free(place_holder);
free(curr_url);
fclose(url_file);
fclose(filepaths_file);
break;
}
curl_easy_cleanup(curl);
......@@ -159,9 +158,9 @@ download_file(char *url, char *filepath, CURL *curl)
}
char*
get_default_filepath(char *url)
get_default_filepath(char *url, char *place_holder)
{
char *url_copy = malloc(strlen(url) + 1);
char *url_copy = realloc(place_holder, strlen(url) + 1);
if (!url_copy) {
die("Malloc failed!");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment