glBindFramebuffer memory leak?

Hi,
Every time I bind a new vbo with glBindFramebuffer valgrind detects memory leak of 64 bytes in two blocks. If I never bind the fbo no memory leak is detected. I have been wondering if this could be a bug in the nvidia drivers or am I just using fbos imporperly?
Otherwise fbos work great and opengl gives no errors.

My gpu is GTX 460 and driver version is 280.13

Here is an example code I used to reproduce the problem:

#include <SDL/SDL.h>
#include <GL/glew.h>

SDL_Surface *s;
GLuint fbo;

int main()
{
	SDL_Init(SDL_INIT_VIDEO);
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	s = SDL_SetVideoMode(800, 600, 16, SDL_OPENGL);
	glewInit();

	glGenFramebuffers(1, &fbo);

	/* If I remove this, total memory leak is 64 bytes smaller */
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glDeleteFramebuffers(1, &fbo);

	SDL_FreeSurface(s);
	SDL_Quit();
	return 0;
}

And valgrind output:

==1871== Memcheck, a memory error detector
==1871== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==1871== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==1871== Command: ./a.out
==1871== 
==1871== Syscall param writev(vector[...]) points to uninitialised byte(s)
==1871==    at 0x42E451E: writev (in /lib/libc-2.14.so)
==1871==    by 0x40004: ???
==1871==  Address 0x60b3403 is 5,283 bytes inside a block of size 16,384 alloc'd
==1871==    at 0x4026416: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1871==    by 0x5D0A6B1: XOpenDisplay (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x408888B: ??? (in /usr/lib/libSDL-1.2.so.0.11.3)
==1871==    by 0x40936F3: ??? (in /usr/lib/libSDL-1.2.so.0.11.3)
==1871==    by 0x407F5E8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3)
==1871==    by 0x4053189: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3)
==1871==    by 0x4233232: (below main) (in /lib/libc-2.14.so)
==1871== 
==1871== 
==1871== HEAP SUMMARY:
==1871==     in use at exit: 32,044 bytes in 853 blocks
==1871==   total heap usage: 13,808 allocs, 12,955 frees, 9,586,533 bytes allocated
==1871== 
==1871== 24 bytes in 4 blocks are definitely lost in loss record 14 of 102
==1871==    at 0x4027C98: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1871==    by 0x428FF50: strdup (in /lib/libc-2.14.so)
==1871==    by 0x73: ???
==1871== 
==1871== 80 bytes in 2 blocks are definitely lost in loss record 75 of 102
==1871==    at 0x4027C98: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1871==    by 0x4174C68: ??? (in /usr/lib/libGL.so.280.13)
==1871== 
==1871== 80 bytes in 2 blocks are definitely lost in loss record 76 of 102
==1871==    at 0x4027C98: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1871==    by 0x4174C78: ??? (in /usr/lib/libGL.so.280.13)
==1871== 
==1871== 112 (8 direct, 104 indirect) bytes in 1 blocks are definitely lost in loss record 82 of 102
==1871==    at 0x4027D82: realloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1871==    by 0x5D2E2A6: ??? (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x5D2E7A2: ??? (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x5D3012F: ??? (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x5D309BA: _XlcCreateLC (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x5D4F7F9: _XlcDefaultLoader (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x5D38793: _XOpenLC (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x5D388F1: _XlcCurrentLC (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x40938CB: ??? (in /usr/lib/libSDL-1.2.so.0.11.3)
==1871==    by 0x407F5E8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3)
==1871==    by 0x4053189: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3)
==1871==    by 0x4233232: (below main) (in /lib/libc-2.14.so)
==1871== 
==1871== 400 bytes in 1 blocks are definitely lost in loss record 86 of 102
==1871==    at 0x4027C98: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1871==    by 0x5D18DE4: XGetVisualInfo (in /usr/lib/libX11.so.6.3.0)
==1871==    by 0x41: ???
==1871== 
==1871== LEAK SUMMARY:
==1871==    definitely lost: 592 bytes in 10 blocks
==1871==    indirectly lost: 104 bytes in 4 blocks
==1871==      possibly lost: 0 bytes in 0 blocks
==1871==    still reachable: 31,348 bytes in 839 blocks
==1871==         suppressed: 0 bytes in 0 blocks
==1871== Reachable blocks (those to which a pointer was found) are not shown.
==1871== To see them, rerun with: --leak-check=full --show-reachable=yes
==1871== 
==1871== For counts of detected and suppressed errors, rerun with: -v
==1871== Use --track-origins=yes to see where uninitialised values come from
==1871== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 69 from 10)

Also valgrind output of version without glBindFramebuffer call:

==1886== Memcheck, a memory error detector
==1886== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==1886== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==1886== Command: ./a.out
==1886== 
==1886== Syscall param writev(vector[...]) points to uninitialised byte(s)
==1886==    at 0x42E451E: writev (in /lib/libc-2.14.so)
==1886==    by 0x40004: ???
==1886==  Address 0x60b3403 is 5,283 bytes inside a block of size 16,384 alloc'd
==1886==    at 0x4026416: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1886==    by 0x5D0A6B1: XOpenDisplay (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x408888B: ??? (in /usr/lib/libSDL-1.2.so.0.11.3)
==1886==    by 0x40936F3: ??? (in /usr/lib/libSDL-1.2.so.0.11.3)
==1886==    by 0x407F5E8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3)
==1886==    by 0x4053189: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3)
==1886==    by 0x4233232: (below main) (in /lib/libc-2.14.so)
==1886== 
==1886== 
==1886== HEAP SUMMARY:
==1886==     in use at exit: 31,980 bytes in 851 blocks
==1886==   total heap usage: 13,713 allocs, 12,862 frees, 9,499,152 bytes allocated
==1886== 
==1886== 24 bytes in 4 blocks are definitely lost in loss record 14 of 102
==1886==    at 0x4027C98: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1886==    by 0x428FF50: strdup (in /lib/libc-2.14.so)
==1886==    by 0x73: ???
==1886== 
######## 32 bytes smaller leak here
==1886== 48 bytes in 1 blocks are definitely lost in loss record 69 of 102
==1886==    at 0x4027C98: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1886==    by 0x4174C68: ??? (in /usr/lib/libGL.so.280.13)
==1886== 
######## also 32 bytes less here
==1886== 48 bytes in 1 blocks are definitely lost in loss record 70 of 102
==1886==    at 0x4027C98: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1886==    by 0x4174C78: ??? (in /usr/lib/libGL.so.280.13)
==1886== 
==1886== 112 (8 direct, 104 indirect) bytes in 1 blocks are definitely lost in loss record 82 of 102
==1886==    at 0x4027D82: realloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1886==    by 0x5D2E2A6: ??? (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x5D2E7A2: ??? (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x5D3012F: ??? (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x5D309BA: _XlcCreateLC (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x5D4F7F9: _XlcDefaultLoader (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x5D38793: _XOpenLC (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x5D388F1: _XlcCurrentLC (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x40938CB: ??? (in /usr/lib/libSDL-1.2.so.0.11.3)
==1886==    by 0x407F5E8: SDL_VideoInit (in /usr/lib/libSDL-1.2.so.0.11.3)
==1886==    by 0x4053189: SDL_InitSubSystem (in /usr/lib/libSDL-1.2.so.0.11.3)
==1886==    by 0x4233232: (below main) (in /lib/libc-2.14.so)
==1886== 
==1886== 400 bytes in 1 blocks are definitely lost in loss record 86 of 102
==1886==    at 0x4027C98: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1886==    by 0x5D18DE4: XGetVisualInfo (in /usr/lib/libX11.so.6.3.0)
==1886==    by 0x41: ???
==1886== 
==1886== LEAK SUMMARY:
==1886==    definitely lost: 528 bytes in 8 blocks
==1886==    indirectly lost: 104 bytes in 4 blocks
==1886==      possibly lost: 0 bytes in 0 blocks
==1886==    still reachable: 31,348 bytes in 839 blocks
==1886==         suppressed: 0 bytes in 0 blocks
==1886== Reachable blocks (those to which a pointer was found) are not shown.
==1886== To see them, rerun with: --leak-check=full --show-reachable=yes
==1886== 
==1886== For counts of detected and suppressed errors, rerun with: -v
==1886== Use --track-origins=yes to see where uninitialised values come from
==1886== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 69 from 10)

Only fbo are producing this ? Have you tried with other objects like vbo,vao, simple textures ?

Yes, this only occurs with fbos.

And without glew ?

It happens without glew too. I also tried creating opengl context directly with xlib and glx, but it didn’t help either.

As far as I remember, the NVidia drivers uses self-modifying code which could confuse valgrind. You have to use the --smc-check=all parameter to get accurate results.

I ran valgrind with “valgrind --smc-check=all --leak-check=full”, but it still detects memory leak.

I would suggest to check with nvidia directly. It looks to be a driver bug.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.