Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Plug memory leaks #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 30 additions & 7 deletions src/QS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ void mainRoutine(unsigned long Mdiv2, mpz_t n, unsigned long multiplier)
gmp_printf("%Zd\n",temp);
}
}
free(nullrows);
mpz_clear(factor);
return;
}
Expand Down Expand Up @@ -1644,21 +1645,43 @@ int main(int argc, char *argv[])
#endif
if (tmp_dir == NULL) tmp_dir = "./";
char * delfile;
char * unique_name;

delfile = get_filename(tmp_dir,unique_filename("comb"));
unique_name = unique_filename("comb");
delfile = get_filename(tmp_dir,unique_name);
remove(delfile);
delfile = get_filename(tmp_dir,unique_filename("frels"));
free(delfile);
free(unique_name);
unique_name = unique_filename("frels");
delfile = get_filename(tmp_dir,unique_name);
remove(delfile);
delfile = get_filename(tmp_dir,unique_filename("flprels"));
free(delfile);
free(unique_name);
unique_name = unique_filename("flprels");
delfile = get_filename(tmp_dir,unique_name);
remove(delfile);
delfile = get_filename(tmp_dir,unique_filename("lpnew"));
free(delfile);
free(unique_name);
unique_name = unique_filename("lpnew");
delfile = get_filename(tmp_dir,unique_name);
remove(delfile);
delfile = get_filename(tmp_dir,unique_filename("rels"));
free(delfile);
free(unique_name);
unique_name = unique_filename("rels");
delfile = get_filename(tmp_dir,unique_name);
remove(delfile);
delfile = get_filename(tmp_dir,unique_filename("fnew"));
free(delfile);
free(unique_name);
unique_name = unique_filename("fnew");
delfile = get_filename(tmp_dir,unique_name);
remove(delfile);
delfile = get_filename(tmp_dir,unique_filename("lprels"));
free(delfile);
free(unique_name);
unique_name = unique_filename("lprels");
delfile = get_filename(tmp_dir,unique_name);
remove(delfile);
free(delfile);
free(unique_name);

return 0;
}
Expand Down
16 changes: 13 additions & 3 deletions src/lprels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ FILE * flint_fopen(char * name, char * mode)
char * tmp_dir = getenv("TMPDIR");
#endif
if (tmp_dir == NULL) tmp_dir = "./";
FILE * temp_file = fopen(get_filename(tmp_dir,unique_filename(name)),mode);
char * unique_name = unique_filename(name);
char * file_name = get_filename(tmp_dir,unique_name);
FILE * temp_file = fopen(file_name,mode);
free(file_name);
free(unique_name);
if (!temp_file)
{
printf("Unable to open temporary file\n");
Expand Down Expand Up @@ -497,10 +501,14 @@ long mergesort_lp_file(char *REL_str, char *NEW_str, char *TMP_str, FILE *COMB)
char * tmp_dir = getenv("TMPDIR");
#endif
if (tmp_dir == NULL) tmp_dir = "./";
char * TMP_name = get_filename(tmp_dir,unique_filename(TMP_str));
char * REL_name = get_filename(tmp_dir,unique_filename(REL_str));
char * TMP_unique = unique_filename(TMP_str);
char * REL_unique = unique_filename(REL_str);
char * TMP_name = get_filename(tmp_dir,TMP_unique);
char * REL_name = get_filename(tmp_dir,REL_unique);
FILE * TMP = fopen(TMP_name,"w");
FILE * REL = fopen(REL_name,"r");
free(REL_unique);
free(TMP_unique);
if ((!TMP) || (!REL))
{
printf("Unable to open temporary file\n");
Expand All @@ -516,6 +524,8 @@ long mergesort_lp_file(char *REL_str, char *NEW_str, char *TMP_str, FILE *COMB)
printf("Cannot rename file %s to %s", TMP_str, REL_str);
abort();
}
free(REL_name);
free(TMP_name);
return tp;
}

Expand Down