Index: fact/tools/rootmacros/PulseTemplates/rootfilehandler.C
===================================================================
--- fact/tools/rootmacros/PulseTemplates/rootfilehandler.C	(revision 13616)
+++ fact/tools/rootmacros/PulseTemplates/rootfilehandler.C	(revision 13617)
@@ -27,22 +27,27 @@
 
 
-TFile*
+void
 OpenRootFile(
-        const char * loc_fname,
-        int verbosityLevel
+        TFile*          output_rootfile,
+        const char *    loc_fname,
+        int             verbosityLevel
         )
 {
-    TFile* tf = new TFile(loc_fname,"UPDATE");
-    if (tf->IsZombie())
+    output_rootfile = new TFile(loc_fname,"UPDATE");
+    if (output_rootfile->IsZombie())
     {
         cout << "Error opening file" << endl;
         exit(-1);
     }
-    else {
-        if (verbosityLevel > 1) cout << "...opening root-file:"
-                                     << loc_fname
-                                     << " successfull" << endl;
+    else
+    {
+        if (verbosityLevel > 1)
+        {
+            cout << "...opening root-file:"
+                 << loc_fname
+                 << " successfull" << endl;
+        }
     }
-    return tf;
+    return;
 }
 //end of OpenRootFile
@@ -52,13 +57,14 @@
 void
 CloseRootFile(
-        TFile* tf
+        TFile* output_rootfile
         )
 {
-    if (tf->IsZombie())
+    if (output_rootfile->IsZombie())
     {
     cout << "Error closing file" << endl;
     exit(-1);
     } else {
-    tf->Close();
+    output_rootfile->Close();
+    delete output_rootfile;
     }
 }
@@ -81,18 +87,19 @@
                                  << subdirectory << endl ;
 
-    TFile* tf = OpenRootFile(loc_fname, verbosityLevel);
+    TFile* output_rootfile = NULL;
+    OpenRootFile(output_rootfile, loc_fname, verbosityLevel);
     if ( !( subdirectory.CompareTo("root") ) ) //if subdirectory = root
     {
-        tf->cd();
+        output_rootfile->cd();
     }
     else
     {
-        tf->cd();
-        tf->mkdir(subdirectory,subdirectory);
-        tf->cd(subdirectory);
+        output_rootfile->cd();
+        output_rootfile->mkdir(subdirectory,subdirectory);
+        output_rootfile->cd(subdirectory);
     }
     histList->Write(); // write the major histograms into the top level directory
     if (verbosityLevel > 3) tf->ls();
-    CloseRootFile( tf ); // close the file
+    CloseRootFile( output_rootfile ); // close the file
     if (verbosityLevel > 2) cout << "...done" << endl;
 }
