When setBuffer() is not being called, outputBuffer is a NULL pointer as initialised in the constructor. https://github.com/fmihpc/vlsv/blob/master/vlsv_writer.cpp#L53 It seems that this situation leads to malloc probblems/OOM crashes in Vlasiator in some cases when it tries to empty the buffer before writing at https://github.com/fmihpc/vlsv/blob/master/vlsv_writer.cpp#L549.
When setBuffer() is called with an argument of 0, which should behave similarly as the default behaviour when the function is not called when looking at the rest of the code, what happens is that outputBuffer is set as a well-behaving zero-length char array https://github.com/fmihpc/vlsv/blob/master/vlsv_writer.cpp#L830. This does not lead to the crashes otherwise detected.
Now looking at the top of setBuffer(), if the user calls setBuffer() a second time and there is data left in the buffer, it will be silently deallocated and a new one will be allocated. Should this call emptyBuffer() first? Or should the user simply be prevented from calling setBuffer() multiple times, and then the delete is not needed any more?
Until this is solved we recommend to call setBuffer(0) or with the desired buffer size once and only once before any writing sequence.
When
setBuffer()is not being called,outputBufferis a NULL pointer as initialised in the constructor. https://github.com/fmihpc/vlsv/blob/master/vlsv_writer.cpp#L53 It seems that this situation leads to malloc probblems/OOM crashes in Vlasiator in some cases when it tries to empty the buffer before writing at https://github.com/fmihpc/vlsv/blob/master/vlsv_writer.cpp#L549.When
setBuffer()is called with an argument of 0, which should behave similarly as the default behaviour when the function is not called when looking at the rest of the code, what happens is thatoutputBufferis set as a well-behaving zero-lengthchararray https://github.com/fmihpc/vlsv/blob/master/vlsv_writer.cpp#L830. This does not lead to the crashes otherwise detected.Now looking at the top of
setBuffer(), if the user callssetBuffer()a second time and there is data left in the buffer, it will be silently deallocated and a new one will be allocated. Should this callemptyBuffer()first? Or should the user simply be prevented from callingsetBuffer()multiple times, and then thedeleteis not needed any more?Until this is solved we recommend to call
setBuffer(0)or with the desired buffer size once and only once before any writing sequence.