Dr. Canal:
To make sure that it wasn’t a memory management problem introduced by my editing and moving
malloc to new, I recompiled the almost original code (when I correctly use rootcint and
include the dictionary code, it works!), I got the same results. This is the edited output from
valgrind:
*** Break *** segmentation violation
==3023==
==3023== Invalid read of size 4
==3023== at 0x42E0F25: TUnixSystem::StackTrace() (in /opt/cern/root/lib/libCore.so)
==3023== by 0x42DE8AD: TUnixSystem::DispatchSignals(ESignals) (in /opt/cern/root/lib/libCore.so)
==3023== by 0x42DE97C: SigHandler(ESignals) (in /opt/cern/root/lib/libCore.so)
==3023== by 0x42D7A73: sighandler(int) (in /opt/cern/root/lib/libCore.so)
==3023== by 0xD079D7: (within /lib/libpthread-2.7.so)
==3023== by 0x4294311: TClass::GetActualClass(void const*) const (in /opt/cern/root/lib/libCore.so)
==3023== by 0x596EEDA: TTree::BranchImp(char const*, char const*, TClass*, void*, int, int) (in /opt/cern/root/lib/libTree.so)
==3023== by 0x8060AC8: TBranch* TTree::Branch<_ncData>(char const*, char const*, _ncData**, int, int) (in /home/dbrunk/newtry/22)
==3023== by 0x80609B5: main (in /home/dbrunk/newtry/22)
==3023== Address 0x0 is not stack’d, malloc’d or (recently) free’d
==3023==
==3023== Process terminating with default action of signal 11 (SIGSEGV)
==3023== Access not within mapped region at address 0x0
==3023== at 0x42E0F25: TUnixSystem::StackTrace() (in /opt/cern/root/lib/libCore.so)
==3023== by 0x42DE8AD: TUnixSystem::DispatchSignals(ESignals) (in /opt/cern/root/lib/libCore.so)
==3023== by 0x42DE97C: SigHandler(ESignals) (in /opt/cern/root/lib/libCore.so)
==3023== by 0x42D7A73: sighandler(int) (in /opt/cern/root/lib/libCore.so)
==3023== by 0xD079D7: (within /lib/libpthread-2.7.so)
==3023== by 0x4294311: TClass::GetActualClass(void const*) const (in /opt/cern/root/lib/libCore.so)
==3023== by 0x596EEDA: TTree::BranchImp(char const*, char const*, TClass*, void*, int, int) (in /opt/cern/root/lib/libTree.so)
==3023== by 0x8060AC8: TBranch* TTree::Branch<_ncData>(char const*, char const*, _ncData**, int, int) (in /home/dbrunk/newtry/22)
==3023== by 0x80609B5: main (in /home/dbrunk/newtry/22)
==3023==
==3023== ERROR SUMMARY: 45 errors from 5 contexts (suppressed: 54 from 1)
==3023== malloc/free: in use at exit: 4,343,659 bytes in 30,632 blocks.
==3023== malloc/free: 53,962 allocs, 23,330 frees, 5,853,130 bytes allocated.
==3023== For counts of detected errors, rerun with: -v
==3023== searching for pointers to 30,632 not-freed blocks.
==3023== checked 9,365,668 bytes.
==3023==
==3023== LEAK SUMMARY:
==3023== definitely lost: 354 bytes in 8 blocks.
==3023== possibly lost: 108,439 bytes in 2,535 blocks.
==3023== still reachable: 4,234,866 bytes in 28,089 blocks.
==3023== suppressed: 0 bytes in 0 blocks.
==3023== Rerun with --leak-check=full to see details of leaked memory.
Segmentation fault
The output with the code I posted earlier is very different. Valgrind output:
Error in TStreamerInfo::Build: _Variables, discarding: short* short_data, no [dimension]
==3039==
==3039== Invalid read of size 4
==3039== at 0x4F5C832: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E84E78: TBufferFile::WriteClassBuffer(TClass const*, void*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4295228: TClass::Streamer(void*, TBuffer&, TClass const*) const (in /opt/cern/root/lib/libCore.so)
==3039== by 0x4E87091: TBufferFile::WriteObjectClass(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83DEF: TBufferFile::WriteObjectAny(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83F14: TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4F5B973: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x5928239: TBranchElement::FillLeaves(TBuffer&) (in /opt/cern/root/lib/libTree.so)
==3039== by 0x59213B5: TBranch::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x592699A: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x5926897: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x5971026: TTree::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== Address 0x64E9A7C is 0 bytes after a block of size 4 alloc’d
==3039== at 0x400595C: operator new (vg_replace_malloc.c:195)
==3039== by 0x805763D: ncx_getdimensions(ncData*) (in /home/dbrunk/edit/13)
==3039== by 0x805782A: ncx_read(ncData*) (in /home/dbrunk/edit/13)
==3039== by 0x8057994: main (in /home/dbrunk/edit/13)
==3039==
==3039== Invalid read of size 4
==3039== at 0x4F5A6B8: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E84E78: TBufferFile::WriteClassBuffer(TClass const*, void*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4295228: TClass::Streamer(void*, TBuffer&, TClass const*) const (in /opt/cern/root/lib/libCore.so)
==3039== by 0x4E87091: TBufferFile::WriteObjectClass(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83DEF: TBufferFile::WriteObjectAny(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83F14: TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4F5B973: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x5928239: TBranchElement::FillLeaves(TBuffer&) (in /opt/cern/root/lib/libTree.so)
==3039== by 0x59213B5: TBranch::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x592699A: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x5926897: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x5971026: TTree::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== Address 0x64E9A80 is 4 bytes after a block of size 4 alloc’d
==3039== at 0x400595C: operator new (vg_replace_malloc.c:195)
==3039== by 0x805763D: ncx_getdimensions(ncData*) (in /home/dbrunk/edit/13)
==3039== by 0x805782A: ncx_read(ncData*) (in /home/dbrunk/edit/13)
==3039== by 0x8057994: main (in /home/dbrunk/edit/13)
==3039==
==3039== Invalid read of size 4
==3039== at 0x4F5CDD8: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E84E78: TBufferFile::WriteClassBuffer(TClass const*, void*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4295228: TClass::Streamer(void*, TBuffer&, TClass const*) const (in /opt/cern/root/lib/libCore.so)
==3039== by 0x4E87091: TBufferFile::WriteObjectClass(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83DEF: TBufferFile::WriteObjectAny(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83F14: TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4F5B973: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x5928239: TBranchElement::FillLeaves(TBuffer&) (in /opt/cern/root/lib/libTree.so)
==3039== by 0x59213B5: TBranch::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x592699A: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x5926897: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x5971026: TTree::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== Address 0x64E9A84 is 8 bytes after a block of size 4 alloc’d
==3039== at 0x400595C: operator new (vg_replace_malloc.c:195)
==3039== by 0x805763D: ncx_getdimensions(ncData*) (in /home/dbrunk/edit/13)
==3039== by 0x805782A: ncx_read(ncData*) (in /home/dbrunk/edit/13)
==3039== by 0x8057994: main (in /home/dbrunk/edit/13)
==3039==
==3039== Invalid read of size 4
==3039== at 0x4E83EE2: TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4F5B973: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E84E78: TBufferFile::WriteClassBuffer(TClass const*, void*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4295228: TClass::Streamer(void*, TBuffer&, TClass const*) const (in /opt/cern/root/lib/libCore.so)
==3039== by 0x4E87091: TBufferFile::WriteObjectClass(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83DEF: TBufferFile::WriteObjectAny(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83F14: TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4F5B973: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x5928239: TBranchElement::FillLeaves(TBuffer&) (in /opt/cern/root/lib/libTree.so)
==3039== by 0x59213B5: TBranch::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x592699A: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x5926897: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== Address 0x64F1228 is not stack’d, malloc’d or (recently) free’d
==3039==
==3039== Invalid read of size 4
==3039== at 0x4E83EFF: TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4F5B973: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E84E78: TBufferFile::WriteClassBuffer(TClass const*, void*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4295228: TClass::Streamer(void*, TBuffer&, TClass const*) const (in /opt/cern/root/lib/libCore.so)
==3039== by 0x4E87091: TBufferFile::WriteObjectClass(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83DEF: TBufferFile::WriteObjectAny(void const*, TClass const*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4E83F14: TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x4F5B973: int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, int, int, int, int) (in /opt/cern/root/lib/libRIO.so)
==3039== by 0x5928239: TBranchElement::FillLeaves(TBuffer&) (in /opt/cern/root/lib/libTree.so)
==3039== by 0x59213B5: TBranch::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x592699A: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== by 0x5926897: TBranchElement::Fill() (in /opt/cern/root/lib/libTree.so)
==3039== Address 0x64F1228 is not stack’d, malloc’d or (recently) free’d
==3039==
==3039== ERROR SUMMARY: 16 errors from 7 contexts (suppressed: 54 from 1)
==3039== malloc/free: in use at exit: 4,668,692 bytes in 50,926 blocks.
==3039== malloc/free: 330,212 allocs, 279,286 frees, 16,643,113 bytes allocated.
==3039== For counts of detected errors, rerun with: -v
==3039== searching for pointers to 50,926 not-freed blocks.
==3039== checked 7,382,768 bytes.
==3039==
==3039== LEAK SUMMARY:
==3039== definitely lost: 21,256 bytes in 130 blocks.
==3039== possibly lost: 290,840 bytes in 7,142 blocks.
==3039== still reachable: 4,356,596 bytes in 43,654 blocks.
==3039== suppressed: 0 bytes in 0 blocks.
==3039== Rerun with --leak-check=full to see details of leaked memory.
I tried to follow your previous advice on indicating the length of the arrays and did not know how to do
that. I have that information available, but could not get the code as I read your instructions to work.
I assumed these errors are from when the case/switch is executed to determine the type of data being
stored.
/* Determine what type the attribute is. */
switch(att->atttype)
{
case NC_LONG:
unsigned int n_long;
// unsigned int longptr;
n_long = att->attlength;
// long* = att->att->long_val;
att->long_val = new long[n_long];
/* Retrieve the attribute value. */
if((status=nc_get_att_long(data->fid,varid,att->attname,att->long_val) != NC_NOERR))
{
printf("\n%s\n", nc_strerror(status));
/* Return failure. */
return EXIT_FAILURE;
}
break;
case NC_CHAR:
/* Allocate memory. */
unsigned int n_char ;
// unsigned int charptr;
// charptr* = n_char;
n_char = att->attlength;
att->char_val = new char[n_char];
/* Retrieve the attribute value. */
if((status=nc_get_att_text(data->fid,varid,att->attname,att->char_val) != NC_NOERR))
{
printf("\n%s\n", nc_strerror(status));
/* Return failure. */
return EXIT_FAILURE;
}
break;
case NC_DOUBLE:
/* Allocate memory. */
unsigned int n_double ;
// unsigned int doubleptr;
// doubleptr* = n_double;
n_double = att->attlength;
att->double_val = new double[n_double];
/* Retrieve the attribute value. */
if((status=nc_get_att_double(data->fid,varid,att->attname,att->double_val) != NC_NOERR))
{
printf("\n%s\n", nc_strerror(status));
/* Return failure. */
return EXIT_FAILURE;
}
break;
case NC_FLOAT:
/* Allocate memory. */
unsigned int n_float ;
// unsigned int floatptr;
// floatprt = n_float;
n_float = att->attlength;
att->float_val = new float[n_float];
/* Retrieve the attribute value. */ ..........
I rewrote malloc to new using unsigned int n_datatype, so thought that since long is a reserved
word I needed a pointer new variable to that value. But this does not work. I commented out the
code and returned to being able to compile the code. I found fArraySize is in ALICE but did not
understand that usage either.