I'm having a problem regarding memory. I will show you both my Valgrind output and source code. I really can't figure out what I'm doing wrong or how to fix the errors Valgrind is giving me.
Valgrind finds the following problems in my program:
==6040== Conditional jump or move depends on uninitialised value(s)
==6040== at 0xC2F91EA: ??? (in /usr/lib/nvidia-304-updates/libnvidia-glcore.so.304.125)
==6040== by 0xC2F96EF: ??? (in /usr/lib/nvidia-304-updates/libnvidia-glcore.so.304.125)
==6040== by 0xE01BFFF: ??? (in /dev/nvidia0)
==6040== Uninitialised value was created by a stack allocation
==6040== at 0x4E8F3D0: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==6040==
==6040== Conditional jump or move depends on uninitialised value(s)
==6040== at 0xC6AB97D: ??? (in /usr/lib/nvidia-304-updates/libnvidia-glcore.so.304.125)
==6040== Uninitialised value was created by a stack allocation
==6040== at 0x4E8F3D0: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==6040==
==6040== Conditional jump or move depends on uninitialised value(s)
==6040== at 0xC6AB986: ??? (in /usr/lib/nvidia-304-updates/libnvidia-glcore.so.304.125)
==6040== Uninitialised value was created by a stack allocation
==6040== at 0x4E8F3D0: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==6040==
==6040== Conditional jump or move depends on uninitialised value(s)
==6040== at 0xC6ABA28: ??? (in /usr/lib/nvidia-304-updates/libnvidia-glcore.so.304.125)
==6040== Uninitialised value was created by a stack allocation
==6040== at 0x4E8F3D0: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==6040==
==6040==
==6040== HEAP SUMMARY:
==6040== in use at exit: 35,600 bytes in 431 blocks
==6040== total heap usage: 11,048 allocs, 10,617 frees, 14,074,851 bytes allocated
==6040==
==6040== LEAK SUMMARY:
==6040== definitely lost: 60 bytes in 7 blocks
==6040== indirectly lost: 0 bytes in 0 blocks
==6040== possibly lost: 0 bytes in 0 blocks
==6040== still reachable: 35,540 bytes in 424 blocks
==6040== suppressed: 0 bytes in 0 blocks
==6040== Rerun with --leak-check=full to see details of leaked memory
==6040==
==6040== For counts of detected and suppressed errors, rerun with: -v
==6040== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 6 from 1)
This is my source code:
#include <stdio.h>
#include <SDL2/SDL.h>
typedef struct gameState
{
SDL_Window* window;
SDL_Renderer* renderer;
}
gameState;
void exitGame(gameState* game);
int main(void)
{
gameState game = {NULL};
// initialize SDL library
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
fprintf(stderr, "Initialization error: %s", SDL_GetError());
SDL_Quit();
return 1;
}
// create game window
game.window = SDL_CreateWindow(
"Game",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
160,
144,
0
);
if (game.window == NULL)
{
fprintf(stderr, "Window error: %s\n", SDL_GetError());
SDL_Quit;
return 1;
}
game.renderer = SDL_CreateRenderer(game.window, -1, 0);
if (game.renderer == NULL)
{
fprintf(stderr, "Renderer error: %s\n", SDL_GetError());
SDL_DestroyWindow(game.window);
SDL_Quit();
return 1;
}
exitGame(&game);
return 0;
}
void exitGame(gameState* game)
{
SDL_DestroyRenderer(game->renderer);
SDL_DestroyWindow(game->window);
SDL_Quit();
}