| Summary: | possible memory leak,use sdl and sdl_image lib | ||
|---|---|---|---|
| Product: | SDL_image | Reporter: | peter <zhuxiaoqiang> |
| Component: | misc | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | ||
| Version: | 1.2.6 | ||
| Hardware: | x86 | ||
| OS: | Linux | ||
| Bug Depends on: | |||
| Bug Blocks: | 12 | ||
| Attachments: | a png with alpha channel | ||
I don't know if it's a memory leak or something else. How can I fix it. thanks for your help! It's not legal to check the refcount on a surface after it was freed. :) |
Created attachment 308 [details] a png with alpha channel Possible Memory Leak rendering PNG images,the parts code of a sample is belows: //============================================================================ /* Initialize the SDL library */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); return(255); } flags = SDL_SWSURFACE; SDL_Surface* Surf_Temp = NULL; /* Open the image file */ for(j=0;j<100;j++) { image[j] = IMG_Load(argv[1]); } /* Use the deepest native mode, except that we emulate 32bpp for viewing non-indexed images on 8bpp screens */ screen = SDL_SetVideoMode(720, 576, 16, flags); if ( screen == NULL ) { fprintf(stderr,"Couldn't set video mode: %s\n", SDL_GetError()); return -1; } #if 0 /* Set the palette, if one exists */ if ( image[20]->format->palette ) { SDL_SetColors(screen, image[20]->format->palette->colors, 0, image[20]->format->palette->ncolors); } /* Draw a background pattern if the surface has transparency */ if(image[20]->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY)) draw_background(screen); #endif /* Display the image */ SDL_BlitSurface(image[20], NULL, screen, NULL); SDL_UpdateRect(screen,0,0,0,0); sleep(5); fprintf(stderr,"start free resource...................\n"); for(j=0;j<100;j++) { printf("before free:image[%d].refcount is %d\n",j,image[j]->refcount); SDL_FreeSurface(image[j]); printf("after free:image[%d].refcount is %d\n",j,image[j]->refcount); } SDL_Quit(); ...............