title: Returning result of stbi_load function and using it for glTexImage2D causes memory violation
body: <p>I've a problem with the stbi library and I thought, maybe you have an idea why this isn't working. I have declared a function like this:</p>
  
  <pre><code>bool LoadTextureFile(std::string file, unsigned char ** pixel_data, int * width, int * height, int * n);
  </code></pre>
  
  <p>In this function I get the result of stbi_load directly saved in the *pixel_data variable:</p>
  
  <pre><code>*pixel_data = stbi_load(file.c_str(), width, height, n, 0);
  // Do some more stuff till return
  return true;
  </code></pre>
  
  <p>So, now my pixel_data pointer points to the memory of the result of stbi_load. Now I wanna use this result with the glTexImage2D method in my previous function. This function calls the LoadTextureFile method before calling the glTexImage2D method of OpenGL like this:</p>
  
  <pre><code>bool LoadTexture(...)
  {
    int tex_width, tex_height, tex_n;
    unsigned char * pixel_data    = NULL;
    LoadTextureFile(filename, &amp;pixel_data, &amp;tex_width, &amp;tex_height, &amp;tex_n);
    // Do something special ...
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, &amp;pixel_data);
    stbi_image_free(&amp;pixel_data);
    // ...
  }
  </code></pre>
  
  <p>But if I do it like that, then I get a memory violation message at the point of calling the glTexImage2D. 
  If I move this whole magic into the LoadTextureFile, after loading a new texture file with stbi_load, then it works:</p>
  
  <pre><code>bool LoadTextureFile(std::string file, unsigned char ** pixel_data, int * width, int * height, int * n)
  {
    unsigned char * = = stbi_load(file.c_str(), width, height, n, 0);
    // Do some magic ...
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 80, 80, 0, GL_RGB, GL_UNSIGNED_BYTE, pixel_data); 
    stbi_image_free(pixel_data);
    return true;
  }
  </code></pre>
  
  <p>Can someone tell me why I get this message and how to solve this problem?</p>
  
  <p>I guess, it is a matter of keep the reserved memory safe, but I'm not really sure, how to solve it. I tried this in a simple console application before, and there it works.</p>
  
  <p>Thank you for your help!</p>