Valgrind crashes with TH1F::Fit method

Hello,

I am facing a little issue. I want to start chasing after memory leaks in some code I have but at some point, valgrind simply crashes. I, therefore, reproduced the minimal code, which is a fairly simple fit. I might not do it the right way, but anyway I don’t quite get why valgrind cannot handle those few little lines …

#include "TH1F.h"
#include "TF1.h"

int main()
{
  std::cout << "Spectra" << std::endl;
  TH1F* spectra = new TH1F("test","test",100,-1,1);
  spectra -> FillRandom("gaus",100000);
  double mean = 0;

  float pospic = 0; 
  float amppic = 1200; 
  float dump_sigma = 0.2;

  std::cout << "Function" << std::endl;
  TF1 *gaus_pol0 = new TF1("gaus+pol0","gaus(0)+pol0(3)",-1,1);
  gaus_pol0 -> SetParameters(amppic, pospic, dump_sigma, 1);
  gaus_pol0 -> SetRange(-1,1);

  // The error comes here !! See below the output of valgrind
  std::cout << "Fit" << std::endl;
  spectra -> Fit(gaus_pol0,"R+q");

  std::cout << "Extract parameters" << std::endl;
  mean = gaus_pol0->GetParameter(1);
  std::cout << mean << std::endl;

  std::cout << "Delete pointers" << std::endl;
  delete spectra;
  delete gaus_pol0;

  std::cout << "Finish" << std::endl;

  return -1;    
}

I don’t know how much of the error message you need to understand what’s happenning, so I’ll simply print the first paragraphs :

valgrind: m_debuginfo/debuginfo.c:914 (truncate_DebugInfoMapping_overlaps): Assertion '!overlap' failed.

host stacktrace:

==3408==    at 0x58047B6A: show_sched_status_wrk (m_libcassert.c:406)
==3408==    by 0x58047C87: report_and_quit (m_libcassert.c:477)
==3408==    by 0x58047E17: vgPlain_assert_fail (m_libcassert.c:543)
==3408==    by 0x5807A82D: truncate_DebugInfoMapping_overlaps (debuginfo.c:914)
==3408==    by 0x5807A82D: di_notify_ACHIEVE_ACCEPT_STATE (debuginfo.c:965)
==3408==    by 0x5807A82D: vgPlain_di_notify_mmap (debuginfo.c:1319)
==3408==    by 0x580AD6E8: vgModuleLocal_generic_PRE_sys_mmap (syswrap-generic.c:2400)
==3408==    by 0x580B932F: vgSysWrap_amd64_linux_sys_mmap_before (syswrap-amd64-linux.c:413)
==3408==    by 0x580A9041: vgPlain_client_syscall (syswrap-main.c:1914)
==3408==    by 0x580A553A: handle_syscall (scheduler.c:1208)
==3408==    by 0x580A6F82: vgPlain_scheduler (scheduler.c:1526)
==3408==    by 0x580F6640: thread_wrapper (syswrap-linux.c:101)
==3408==    by 0x580F6640: run_a_thread_NORETURN (syswrap-linux.c:154)

sched status:

  running_tid=1

Thread 1: status = VgTs_Runnable syscall 9 (lwpid 3408)
==3408==    at 0x401BE82: __mmap64 (mmap64.c:59)
==3408==    by 0x401BE82: mmap (mmap64.c:47)
==3408==    by 0x400758E: _dl_map_segments (dl-map-segments.h:94)
==3408==    by 0x400758E: _dl_map_object_from_fd (dl-load.c:1186)
==3408==    by 0x4009274: _dl_map_object (dl-load.c:2236)
==3408==    by 0x4013D41: dl_open_worker (dl-open.c:513)
==3408==    by 0x5546A8F: _dl_catch_exception (dl-error-skeleton.c:208)
==3408==    by 0x40138F9: _dl_open (dl-open.c:837)
==3408==    by 0x5603257: dlopen_doit (dlopen.c:66)
==3408==    by 0x5546A8F: _dl_catch_exception (dl-error-skeleton.c:208)
==3408==    by 0x5546B4E: _dl_catch_error (dl-error-skeleton.c:227)
==3408==    by 0x5603A64: _dlerror_run (dlerror.c:170)
==3408==    by 0x56032E3: dlopen@@GLIBC_2.2.5 (dlopen.c:87)

And here the last lines of the backtrace:

==3408==    by 0x6E39059: TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (in /home/corentin/Installation/root/root_install/lib/libCling.so)
==3408==    by 0x49E7DA5: TROOT::ProcessLine(char const*, int*) (in /home/corentin/Installation/root/root_install/lib/libCore.so)
==3408==    by 0x4A25E6C: TObject::AppendPad(char const*) (in /home/corentin/Installation/root/root_install/lib/libCore.so)
==3408==    by 0x5016B82: TH1::Draw(char const*) (in /home/corentin/Installation/root/root_install/lib/libHist.so)
==3408==    by 0x4F3C69D: void HFit::StoreAndDrawFitFunction<TH1>(TH1*, TF1*, ROOT::Fit::DataRange const&, bool, bool, char const*) (in /home/corentin/Installation/root/root_install/lib/libHist.so)
==3408==    by 0x4F42FD0: TFitResultPtr HFit::Fit<TH1>(TH1*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) (in /home/corentin/Installation/root/root_install/lib/libHist.so)
==3408==    by 0x4F37992: ROOT::Fit::FitObject(TH1*, TF1*, Foption_t&, ROOT::Math::MinimizerOptions const&, char const*, ROOT::Fit::DataRange&) (in /home/corentin/Installation/root/root_install/lib/libHist.so)
==3408==    by 0x500D628: TH1::Fit(TF1*, char const*, char const*, double, double) (in /home/corentin/Installation/root/root_install/lib/libHist.so)
==3408==    by 0x10943E: main (TH1F_Fit_breaks_valgrind.cpp:24)
client stack range: [0x1FFEFEF000 0x1FFF000FFF] client SP: 0x1FFEFFD038
valgrind stack range: [0x10032D3000 0x10033D2FFF] top usage: 18424 of 1048576

Tell me if you need any other information!


ROOT Version: 6.26/06
Built for linuxx8664gcc on Sep 26 2022, 15:17:00
From heads/latest-stable@274b476a

Platform: Debian 11.5
Compiler: g++ (Debian 10.2.1-6) 10.2.1 20210110


I guess @moneta can help you.

Hi,
I cannot reproduce your problem. I have run on lxplus with default ROOT and vaklgrind version there and it works fine:

g++ `root-config --cflags --libs` test.C
valgrind ./a.out 

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.