killoshutter.blogg.se

Stb image
Stb image








stb image
  1. #Stb image code#
  2. #Stb image free#

As far as I can see this line is harmless ( free will accept null pointers just fine, if I recall correctly) but it's also useless (the data is always null).

stb image

One is when gr->data is 0 (so no need to free it) and another is when gr->data equals &s (no need to free it either, and it assigns 0 to it before breaking anyway). Second "New!" line: There are two conditions under which the while loop will end. You're not supposed to free that pointer because it's allocated in the stack at the beggining of stbi_xload. That is done because stbi_gif_load_next will return a pointer to the stbi_context when it finds some kind of terminating chunk from the gif format. How could you possibly return any (valid) image data that way? Also note that after that line I'm comparing gr->data with &s. Regarding your first "New!" line: You are freeing the image data as soon as you retrieve it.

#Stb image code#

I won't claim that my code is free from memory leaks, but I see some issues with your changes.įirst, I'm going to assume that where you have gr->out you actually mean gr->data (I'm guessing you renamed it and it's just a typo in the post). GitHub didn't notify me of this and I just found your comment randomly. Sorry, something went sorry I didn't reply earlier. I'm using stb_image - v2.10, and I'm here because a link to this gist is present in that file. Line 5801 in stb_image.h: g->out = (stbi_uc *) stbi_malloc(4 * g->w * g->h) allocated g->out that, according to Valgrind, is never released.Īs I said before, I'm not sure if this happens because of my (slight) modification of your code or if the leak happens in your code as well.

stb image

Line 44: while (gr->data = stbi_gif_load_next(&s, &g, &c, 4)) calls stbi_gif_load_next(stbi_context *s, stbi_gif *g, int *comp, int req_comp) in stb_image.h myFilePathAndLine., but it is correspondent to line 44 of your code myFilePathAndLine., but it is correspondent to line 44 of your codeġ: malloc in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.soĢ: stbi_malloc(unsigned long) in stb_image.h:899ģ: stbi_gif_load_next(stbi_context*, stbi_gif*, int*, int) in stb_image.h:5801Ĥ: ImGui::AnimatedGif::load(char const*) in. In ImGui::AnimatedGif::load(char const*) in. I ask because I'm using a slightly modified version of your code (that's why I'm not sure if the leaks are in your code too :) ), and Valgrind tells me: 388,800 bytes in 1 blocks are definitely lost in loss record 649 of 649 Result = stbi_load_main(&s, x, y, frames, 4) Result = ( unsigned char*) stbi_malloc(*frames * (size + 2)) Gr = (gif_result*) stbi_malloc( sizeof(gif_result)) Return stbi_errpuc( "can't fopen ", "Unable to open file ") STBIDEF unsigned char * stbi_xload( char const *filename, int *x, int *y, int *frames)










Stb image