Ticket #7857 (closed: fixed)

Opened 7 years ago

Last modified 5 years ago

Fix Nexus valgrind errors

Reported by: Russell Taylor Owned by: Russell Taylor
Priority: major Milestone: Release 3.0
Component: Framework Keywords:
Cc: Blocked By:
Blocking: Tester: Michael Reuter

Description

While running valgrind for another reason on FindPeaksTest I noticed several memory errors being highlighted in the LoadNexusProcessed (and called) code:

==7181== Conditional jump or move depends on uninitialised value(s)
==7181==    at 0x4A07F59: strlen (mc_replace_strmem.c:403)
==7181==    by 0x3044A9E14B: std::string::operator=(char const*) (in /usr/lib64/libstdc++.so.6.0.13)
==7181==    by 0x79627E1: Mantid::NeXus::NXClass::getNextEntry() (NexusClasses.cpp:160)
==7181==    by 0x7962AAC: Mantid::NeXus::NXClass::readAllInfo() (NexusClasses.cpp:169)
==7181== Mismatched free() / delete / delete []
==7181==    at 0x4A05B26: operator delete[](void*) (vg_replace_malloc.c:515)
...
==7181==    by 0x68D8DF5: boost::shared_array<int>::~shared_array() (shared_array.hpp:47)
==7181==    by 0x68D8E28: Mantid::NeXus::NXDataSetTyped<int>::~NXDataSetTyped() (NexusClasses.h:198)
==7181==    by 0x697727F: Mantid::DataHandling::LoadNexusProcessed::readInstrumentGroup(Mantid::NeXus::NXEntry&, boost::shared_ptr<Mantid::API::MatrixWorkspace>) (LoadNexusProcessed.cpp:1163)

Change History

comment:1 Changed 7 years ago by Russell Taylor

  • Status changed from new to inprogress

Re #7857. Fix invalid initialisation of shared_array.

A boost::shared_array should be initialised with NULL or a pointer to an array, so what was there were errors. In fact, in these cases there's no need for any initialisation, only declaration.

Changeset: e8622703cfde583bff5ee3bef6973e75cc20275b

comment:2 Changed 7 years ago by Russell Taylor

Re #7857. Only initialise struct members if status is NX_OK.

If there is no next entry, NXgetnextentry will not have set the nxname & nxclass variables that were passed to it. Therefore, a valgrind complaint is avoided by checking for success & only coping the variables on success.

Changeset: 403a10940f150757258a28d33aaa335bc4dc5395

comment:3 Changed 7 years ago by Russell Taylor

Re #7857. Remove nonsense.

Nothing to do with this ticket, but this gave a ton of warnings when built with clang and if you look at it it was clearly nonsense. (N.B. nd is properly initialised later in the constructor.)

Changeset: 85a22ba6a7d2560c65cac14bece2d13a8ba173cc

comment:4 Changed 7 years ago by Russell Taylor

  • Status changed from inprogress to verify
  • Resolution set to fixed

Tester: Branch is feature/7857_nexus_valgrind_errors.

I suggest testing this by inspection of the code and agreement that things that were wrong before are now right! If you really wanted to you could run valgrind (vanilla, not memcheck or anythin) over the LoadNexusProcessedTest and observe lots of errors before the changes and none after.

comment:5 Changed 7 years ago by Michael Reuter

  • Status changed from verify to verifying
  • Tester set to Michael Reuter

comment:6 Changed 7 years ago by Michael Reuter

The changes look good and the before and after on valgrind is great!

comment:7 Changed 7 years ago by Michael Reuter

  • Status changed from verifying to closed

Merge remote-tracking branch 'origin/feature/7857_nexus_valgrind_errors'

comment:8 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 8702

Note: See TracTickets for help on using tickets.