[cig-commits] [commit] master: close the temp file handle returned by mkstemp (84d64d9)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Fri Sep 5 12:13:59 PDT 2014
Repository : https://github.com/geodynamics/aspect
On branch : master
Link : https://github.com/geodynamics/aspect/compare/112a6cff8eadef8902a3687aab82cf20d93106ce...55640dec1ec936af1f68f07fb9631f0cf18e7652
>---------------------------------------------------------------
commit 84d64d926776edbde9c775518a1262f1cffcfa24
Author: Timo Heister <timo.heister at gmail.com>
Date: Fri Sep 5 15:11:22 2014 -0400
close the temp file handle returned by mkstemp
Otherwise we are leaking open file handles and run out of them at some point.
>---------------------------------------------------------------
84d64d926776edbde9c775518a1262f1cffcfa24
source/postprocess/visualization.cc | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/source/postprocess/visualization.cc b/source/postprocess/visualization.cc
index b4adf67..32f42e0 100644
--- a/source/postprocess/visualization.cc
+++ b/source/postprocess/visualization.cc
@@ -485,6 +485,8 @@ namespace aspect
// find out whether $TMPDIR is set and if so put the file in there
std::string tmp_filename;
+ int tmp_file_desc = -1;
+
{
// Try getting the environment variable for the temporary directory
const char *tmp_filedir = getenv("TMPDIR");
@@ -499,7 +501,7 @@ namespace aspect
// by using a C-style string that mkstemp will then overwrite
char *tmp_filename_x = new char[tmp_filename.size()+1];
std::strcpy(tmp_filename_x, tmp_filename.c_str());
- const int tmp_file_desc = mkstemp(tmp_filename_x);
+ tmp_file_desc = mkstemp(tmp_filename_x);
tmp_filename = tmp_filename_x;
delete []tmp_filename_x;
@@ -548,6 +550,11 @@ namespace aspect
// if necessary
out << *file_contents;
out.close ();
+ if (tmp_file_desc != -1)
+ {
+ close(tmp_file_desc);
+ tmp_file_desc = -1;
+ }
if (tmp_filename != *filename)
{
More information about the CIG-COMMITS
mailing list