From b2c7e3cc99e6cd69639dd5a2dad53ee42facab94 Mon Sep 17 00:00:00 2001
From: Philippe Canal <pcanal@fnal.gov>
Date: Tue, 27 Oct 2009 05:31:56 +0000
Subject: [PATCH] Remove a memory leak in some cases of syntax error in the use
 of aliases. Re-add error messages skipped by the change in revision 30877.

git-svn-id: http://root.cern.ch/svn/root/trunk@30878 27541ba8-7e3a-0410-8455-c3a389f83636
---
 tree/treeplayer/src/TTreeFormula.cxx | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/tree/treeplayer/src/TTreeFormula.cxx b/tree/treeplayer/src/TTreeFormula.cxx
index 839bc7a488c..ec7d4f94781 100644
--- a/tree/treeplayer/src/TTreeFormula.cxx
+++ b/tree/treeplayer/src/TTreeFormula.cxx
@@ -2800,6 +2800,7 @@ Int_t TTreeFormula::DefinedVariable(TString &name, Int_t &action)
             TTreeFormula *subform = new TTreeFormula(cname,subValue,fTree,aliasSofar); // Need to pass the aliases used so far.
 
             if (subform->GetNdim()==0) {
+               delete subform;
                Error("DefinedVariable",
                      "The substitution of the alias \"%s\" by \"%s\" failed.",cname,aliasValue);
                return -3;
@@ -2818,7 +2819,22 @@ Int_t TTreeFormula::DefinedVariable(TString &name, Int_t &action)
          } else { /* assumes strcspn(aliasValue,"[]")!=strlen(aliasValue) */
             TString thisAlias( aliasValue );
             thisAlias += dims;
-            return DefinedVariable(thisAlias,action);
+            Int_t aliasRes = DefinedVariable(thisAlias,action);
+            if (aliasRes<0) {
+               // We failed but DefinedVariable has not printed why yet.
+               // and because we want thoses to be printed _before_ the notice
+               // of the failure of the substitution, we need to print them here.
+               if (aliasRes==-1) {
+                  Error("Compile", " Bad numerical expression : \"%s\"",thisAlias.Data()); 
+               } else if (aliasRes==-2) {
+                  Error("Compile", " Part of the Variable \"%s\" exists but some of it is not accessible or useable",thisAlias.Data()); 
+                  
+               }
+               Error("DefinedVariable",
+                     "The substitution of the alias \"%s\" by \"%s\" failed.",cname,aliasValue);
+               return -3;               
+            }
+            return aliasRes;
          }
       }
    }
-- 
GitLab