Bug in TCanvas::SaveAs C-macro

Sorry for the confusion, the above is the exported macro that was saved from the original canvas. The original macro needs comprehensive data input and looks like

TString path="/some/path/to/data";

void anamissres()
{
  vector<double> ecm = {2.3,2.5,3.0,3.5,4.0,4.3,4.5,5.0,5.5};
  
  TGraph *gim = new TGraph();
  TGraph *gmm = new TGraph();
  
  gim->SetMarkerStyle(20);
  gim->SetMarkerSize(1.0);
  gim->SetMarkerColor(4);
  gim->SetLineColor(4);
  
  gmm->SetMarkerStyle(21);
  gmm->SetMarkerSize(1.0);
  gmm->SetMarkerColor(2);
  gmm->SetLineColor(2);
  
  for (auto x:ecm) {
    TString fname = Form("%sllbar%d_auto_0_ana.root", path.Data(), int(x*10));
    TFile *f = new TFile(fname);
    TTree *t = (TTree*) f->Get("ntp0");
    
    t->Draw("xm*1000>>h1","xmct","goff");
    TH1F *h1 = (TH1F*) gDirectory->Get("h1");
    h1->Fit("gaus");
    double rms_im = h1->GetFunction("gaus")->GetParameter(2);
   
   
    t->Draw("mmiss*1000>>h2","xmct","goff");
    TH1F *h2 = (TH1F*) gDirectory->Get("h2");
    h2->Fit("gaus");
    double rms_mm = h2->GetFunction("gaus")->GetParameter(2);
    
    gim->SetPoint(gim->GetN(), x, rms_im);
    gmm->SetPoint(gmm->GetN(), x, rms_mm);
  }
  
  gmm->Draw("ALP");
  gmm->GetHistogram()->SetMinimum(1);
  gmm->GetHistogram()->SetMaximum(400);
  gmm->GetHistogram()->SetTitle(";x;y");
  gim->Draw("LP same");
  
  gPad->SetLogy();
  gPad->SetGridy();
  
  TLegend *leg = new TLegend(0.2,0.75,0.45,0.9);
  leg->AddEntry(gmm, "entry 1", "PL");
  leg->AddEntry(gim, "entry 2", "PL");
  
  leg->Draw();
}