title: Segfault after the return 0;
body: <p>I would like to use ITK for a simple color-ratio program, but I get a segfault after the return 0; of the main function.
  here is my code.</p>
  
  <pre><code>#include "itkImage.h"
  #include "itkImageFileReader.h"
  #include "itkImageFileWriter.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include "itkRGBPixel.h"
  
  
  const unsigned int  Dimension = 2;
  typedef itk::RGBPixel&lt; unsigned char &gt;       PixelType;
  typedef itk::Image&lt; PixelType, Dimension &gt;   ImageType;
  typedef itk::ImageFileReader&lt; ImageType &gt;    ReaderType;
  typedef itk::ImageFileWriter&lt; ImageType &gt;   WriterType;
  
  int main(int argc, char** argv)
  {   
  std::string input=argv[1], output=argv[2];
  
  //allocation of the image data
  ReaderType::Pointer reader    = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();
  
  reader-&gt;SetFileName(input);
  writer-&gt;SetFileName(output);
  
  reader-&gt;Update(); 
  
  //access image
  ImageType::Pointer image = reader-&gt;GetOutput();
  ImageType::Pointer output_img;
  
   //apparently providing the spacing and origin in ITK is mandatory
  ImageType::SpacingType spacing;
  spacing[0] = 0.33;
  spacing[1] = 0.33;
  image-&gt;SetSpacing(spacing);
  
  ImageType::PointType origin;
  origin[0] = 0.0;
  origin[1] = 0.0;
  image-&gt;SetOrigin(origin);
  
  writer-&gt;SetInput( reader-&gt;GetOutput() ); 
      writer-&gt;Update(); 
  
   return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>It compiles and links without any error messages but I have a segfault during execution.
  By executing the program line by line using gdb, I pinpionted the segfault to the last line of the program: after return 0;</p>
  
  <p>Here is the backtrace</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0xb79099bc in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
  (gdb) bt
  #0  0xb79099bc in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
  #1  0xb7909a4e in std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::~basic_string() ()
  from /usr/lib/i386-linux-gnu/libstdc++.so.6
   #2  0x08065369 in main (argc=3, argv=0xbffff1b4) at /home/thibault/workspace/OU/MachineLearning/Project1/src/itkTry1.cpp:221
  (gdb)
  </code></pre>
  
  <p>and when checking with valgrind:</p>
  
  <pre><code>    ==16671== Memcheck, a memory error detector
      ==16671== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
      ==16671== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
      ==16671== Command: ./ColorRatio clouds2.jpeg coucou.jpeg --track-origins=yes
      ==16671== 
      ==16671== Conditional jump or move depends on uninitialised value(s)
      ==16671==    at 0x4B28DD8: inflateReset2 (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
      ==16671==    by 0x4B28EC7: inflateInit2_ (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
      ==16671==    by 0x4C87E58: ??? (in /usr/lib/libITKniftiio.so.3.20.1)
      ==16671== 
      ==16671== Conditional jump or move depends on uninitialised value(s)
      ==16671==    at 0x4B28DD8: inflateReset2 (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
      ==16671==    by 0x4B28EC7: inflateInit2_ (in /lib/i386-linux-gnu/libz.so.1.2.3.4)
      ==16671== 
      ==16671== Invalid read of size 4
      ==16671==    at 0x47429BC: ??? (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
      ==16671==    by 0x47CE4D2: (below main) (libc-start.c:226)
      ==16671==  Address 0xfffffffc is not stack'd, malloc'd or (recently) free'd
      ==16671== 
      ==16671== 
      ==16671== Process terminating with default action of signal 11 (SIGSEGV)
      ==16671==  Access not within mapped region at address 0xFFFFFFFC
      ==16671==    at 0x47429BC: ??? (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
      ==16671==    by 0x47CE4D2: (below main) (libc-start.c:226)
      ==16671==  If you believe this happened as a result of a stack
      ==16671==  overflow in your program's main thread (unlikely but
      ==16671==  possible), you can try to increase the size of the
      ==16671==  main thread stack using the --main-stacksize= flag.
      ==16671==  The main thread stack size used in this run was 8388608.
      ==16671== 
      ==16671== HEAP SUMMARY:
      ==16671==     in use at exit: 2,352,658 bytes in 63,532 blocks
      ==16671==   total heap usage: 74,071 allocs, 10,539 frees, 14,082,941 bytes allocated
      ==16671== 
      ==16671== LEAK SUMMARY:
      ==16671==    definitely lost: 49 bytes in 2 blocks
      ==16671==    indirectly lost: 0 bytes in 0 blocks
      ==16671==      possibly lost: 1,309,540 bytes in 42,156 blocks
      ==16671==    still reachable: 1,043,069 bytes in 21,374 blocks
      ==16671==         suppressed: 0 bytes in 0 blocks
      ==16671== Rerun with --leak-check=full to see details of leaked memory
      ==16671== 
      ==16671== For counts of detected and suppressed errors, rerun with: -v
      ==16671== Use --track-origins=yes to see where uninitialised values come from
      ==16671== ERROR SUMMARY: 5 errors from 3 contexts (suppressed: 0 from 0)
      Segmentation fault (core dumped)
  </code></pre>
  
  <p>Even with 36000 useless try/catch statments, I still get that same segmentation fault after the main.</p>
  
  <p>Can anyone please help me?</p>
  
  <p>Thank you in advance</p>