title: libharu memory allocation failed while loading image
body: <p>I have some C code trying to use libharu. Although I can use every function of this library (even UTF8) I can hardly draw images. Here is some very basic code:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;math.h&gt;
  #include &lt;setjmp.h&gt;
  #include "hpdf.h"
  
  jmp_buf env;
  
  #ifdef HPDF_DLL
  void  __stdcall
  #else
  void
  #endif
  error_handler  (HPDF_STATUS   error_no,
                  HPDF_STATUS   detail_no,
                  void         *user_data)
  {
      printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
                  (HPDF_UINT)detail_no);
      longjmp(env, 1);
  }
  
  int main (int argc, char **argv)
  {
      HPDF_Doc  pdf;
      HPDF_Font font;
      HPDF_Page page;
      char fname[256];
      HPDF_Image image;
  
      strcpy (fname, argv[0]);
      strcat (fname, ".pdf");
  
      pdf = HPDF_New (error_handler, NULL);
      if (!pdf) {
          printf ("error: cannot create PdfDoc object\n");
          return 1;
      }
  
      /* error-handler */
      if (setjmp(env)) {
          HPDF_Free (pdf);
          return 1;
      }
  
  
      font = HPDF_GetFont (pdf, "Helvetica", NULL);
  
  
      page = HPDF_AddPage (pdf);
  
      HPDF_Page_SetWidth (page, 550);
      HPDF_Page_SetHeight (page, 500);
  
      image = HPDF_LoadPngImageFromFile (pdf, "img.png");
  
  
      HPDF_SaveToFile (pdf, fname);
  
  
      HPDF_Free (pdf);
  
      return 0;
  }
  </code></pre>
  
  <p>When I compile this I have <code>ERROR: error_no=1015, detail_no=0</code>. I have found a similar post in stackoverflow: <a href="https://stackoverflow.com/questions/10771205/why-memory-allocation-failed-whe-hpdf-loadpngimagefromfile-using-libhpdf">this</a>. However although original poster said the problem is solved it hardly helped mine. I moved img.png to a folder and recompiled the file. Changed the code that says <code>/home/name/path/to/img.png</code> which is the direct path to image. Nothing works. I "always" have the same error, but when I change the name of file I have <code>ERROR: error_no=1017, detail_no=2</code> which basicly means program cannot find image (according to reference of libharu) So I deduce that program finds img.png; but, it's strange but, cannot allocate the necessary memory. Which is weird because I cannot see any reason for this program not to allocate memory. I have every kind of permission.</p>
  
  <p>I am using GCC 4.7.2 under Ubuntu Quantal Quetzal and libharu 2.3.0 RC2. Thank you for your help. </p>