<p>valgrind shows some invalid accesses too:</p>

<pre><code>[DEBUG] Compiled with debugging symbols.
[WARN ] Neither --neighbors_file nor --distances_file is specified, so the nearest neighbor search results will not be saved!
[INFO ] Loading 'test_data_3_1000.csv' as CSV data.  Size is 3 x 1000.
[INFO ] Loaded reference data from 'test_data_3_1000.csv' (3 x 1000).
[INFO ] Building reference tree...
[INFO ] Tree built.
[INFO ] Searching for 3 nearest neighbors with dual-tree kd-tree search...
[INFO ] 18080 node combinations were scored.
[INFO ] 43890 base cases were calculated.
[INFO ] Search complete.
==24595== Invalid read of size 1
==24595==    at 0x71562BA: _IO_file_xsputn@@GLIBC_2.2.5 (in /lib/x86_64-linux-gnu/libc-2.21.so)
==24595==    by 0x714C3D8: fwrite (in /lib/x86_64-linux-gnu/libc-2.21.so)
==24595==    by 0x651747D: std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::__ostream_insert&lt;char, std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, char const*, long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==24595==    by 0x8589D9: mlpack::util::PrefixedOutStream::PrefixIfNeeded() (prefixedoutstream_impl.hpp:106)
==24595==    by 0x537428B: void mlpack::util::PrefixedOutStream::BaseLogic&lt;std::ostream&amp; (*)(std::ostream&amp;)&gt;(std::ostream&amp; (* const&amp;)(std::ostream&amp;)) (prefixedoutstream_impl.hpp:34)
==24595==    by 0x5370F0C: mlpack::util::PrefixedOutStream::operator&lt;&lt;(std::ostream&amp; (*)(std::ostream&amp;)) (prefixedoutstream.cpp:112)
==24595==    by 0x535A98E: mlpack::CLI::~CLI() (cli.cpp:71)
==24595==    by 0x535B6B8: mlpack::CLI::Destroy() (cli.cpp:249)
==24595==    by 0x536FFD4: mlpack::util::CLIDeleter::~CLIDeleter() (cli_deleter.cpp:31)
==24595==    by 0x711919E: __cxa_finalize (in /lib/x86_64-linux-gnu/libc-2.21.so)
==24595==    by 0x52F1EA2: ??? (in /home/ryan/src/mlpack-tsp/build/lib/libmlpack.so.2.0)
==24595==    by 0x400F876: _dl_fini (in /lib/x86_64-linux-gnu/ld-2.21.so)
==24595==  Address 0x92d8e92 is 18 bytes inside a block of size 20 free'd
==24595==    at 0x4C2B2CB: operator delete(void*) (vg_replace_malloc.c:575)
==24595==    by 0x5370747: mlpack::util::PrefixedOutStream::~PrefixedOutStream() (prefixedoutstream.hpp:52)
==24595==    by 0x711919E: __cxa_finalize (in /lib/x86_64-linux-gnu/libc-2.21.so)
==24595==    by 0x52F1EA2: ??? (in /home/ryan/src/mlpack-tsp/build/lib/libmlpack.so.2.0)
==24595==    by 0x400F876: _dl_fini (in /lib/x86_64-linux-gnu/ld-2.21.so)
==24595==    by 0x7118E01: __run_exit_handlers (in /lib/x86_64-linux-gnu/libc-2.21.so)
==24595==    by 0x7118E54: exit (in /lib/x86_64-linux-gnu/libc-2.21.so)
==24595==    by 0x7103876: (below main) (in /lib/x86_64-linux-gnu/libc-2.21.so)
==24595==  Block was alloc'd at
==24595==    at 0x4C2A16F: operator new(unsigned long) (vg_replace_malloc.c:333)
==24595==    by 0x6529496: void std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::_M_construct&lt;char const*&gt;(char const*, char const*, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==24595==    by 0x65295EB: std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string(char const*, std::allocator&lt;char&gt; const&amp;) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==24595==    by 0x53706E2: mlpack::util::PrefixedOutStream::PrefixedOutStream(std::ostream&amp;, char const*, bool, bool) (prefixedoutstream.hpp:74)
==24595==    by 0x53705AA: __static_initialization_and_destruction_0(int, int) (log.cpp:44)
==24595==    by 0x537067C: _GLOBAL__sub_I_log.cpp (log.cpp:130)
==24595==    by 0x400F269: call_init.part.0 (in /lib/x86_64-linux-gnu/ld-2.21.so)
==24595==    by 0x400F37A: _dl_init (in /lib/x86_64-linux-gnu/ld-2.21.so)
==24595==    by 0x4000CC9: ??? (in /lib/x86_64-linux-gnu/ld-2.21.so)
==24595==    by 0x5: ???
==24595==    by 0xFFF000682: ???
==24595==    by 0xFFF000694: ???
... (lots more)
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/pull/521#issuecomment-183386914">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFOZv421LOhQJpxGFhuGChJPb0M3wks5pjfnvgaJpZM4HX7Db.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/521#issuecomment-183386914"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>