[Xbubble-commits] xbubble-sdl/src levels.c, 1.1.1.1, 1.2 levels.h,
1.1.1.1, 1.2 theme.c, 1.5, 1.6 theme.h, 1.1.1.1, 1.2 xbubble.c,
1.7, 1.8
Martin Quinson
mquinson at alioth.debian.org
Thu Sep 14 12:35:43 UTC 2006
- Previous message: [Xbubble-commits] xbubble-sdl/src board.c, 1.7, 1.8 board.h, 1.4,
1.5 theme.c, 1.4, 1.5 xbubble.c, 1.6, 1.7
- Next message: [Xbubble-commits] xbubble-sdl/src board.c, 1.8, 1.9 board.h, 1.5,
1.6 game.c, 1.7, 1.8
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/xbubble/xbubble-sdl/src
In directory haydn:/tmp/cvs-serv27926
Modified Files:
levels.c levels.h theme.c theme.h xbubble.c
Log Message:
Plug a bunch of memleaks
Index: levels.c
===================================================================
RCS file: /cvsroot/xbubble/xbubble-sdl/src/levels.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- levels.c 11 Aug 2006 12:14:50 -0000 1.1.1.1
+++ levels.c 14 Sep 2006 12:35:41 -0000 1.2
@@ -54,7 +54,6 @@
thislevel = lev->levels + lev->nb_levels * lev->nb_cells;
-
file = file_resolve_path(file, NULL);
fd = fopen( file, "r" );
@@ -108,6 +107,11 @@
return lev;
}
+void levels_free(levels_t lev) {
+ free(lev->levels);
+ free(lev);
+}
+
int *levels_get_colors(levels_t lev, int num) {
return lev->levels + num * lev->nb_cells ;
}
Index: xbubble.c
===================================================================
RCS file: /cvsroot/xbubble/xbubble-sdl/src/xbubble.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- xbubble.c 14 Sep 2006 09:53:02 -0000 1.7
+++ xbubble.c 14 Sep 2006 12:35:41 -0000 1.8
@@ -17,7 +17,8 @@
screen = window_make(MAX_X,MAX_Y);
- theme_t *theme = theme_init("fancy",zoom);
+ theme_t *theme = theme_load("fancy",zoom);
+
levels_t levels = levels_load("levels.txt");
ruleset_t ruleset = DEFAULT_RULE_SET;
game_t game = game_new(game_mode_single, &ruleset, theme, zoom,
@@ -27,5 +28,10 @@
game_play(game);
+ game_free(game);
+ levels_free(levels);
+ theme_free(theme);
+ SDL_Quit();
+
return 0;
}
Index: levels.h
===================================================================
RCS file: /cvsroot/xbubble/xbubble-sdl/src/levels.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- levels.h 11 Aug 2006 12:14:50 -0000 1.1.1.1
+++ levels.h 14 Sep 2006 12:35:41 -0000 1.2
@@ -4,5 +4,6 @@
typedef struct _levels *levels_t;
levels_t levels_load( const char * file );
+void levels_free(levels_t levels);
int *levels_get_colors(levels_t lev, int num);
#endif /* _LEVELS_H */
Index: theme.c
===================================================================
RCS file: /cvsroot/xbubble/xbubble-sdl/src/theme.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- theme.c 14 Sep 2006 09:53:02 -0000 1.5
+++ theme.c 14 Sep 2006 12:35:41 -0000 1.6
@@ -77,15 +77,14 @@
return animation;
}
-static void animation_free( Set animation ) {
- int i;
- if (animation) {
- for ( i = 0; i < animation->size; i++ )
- frame_free( animation->element[i] );
- set_free( animation );
- }
+static void animation_free(Set a) {
+ while (a->size) {
+ frame_free(a->element[--a->size]);
+ }
+ set_free(a);
}
+
static void animation_unref( Set animation ) {
if (animation && !--animation->ref)
animation_free( animation );
@@ -305,9 +304,15 @@
SDL_BlitSurface(tile, NULL, theme->background, &pos);
}
SDL_Flip(theme->background);
+
+ SDL_FreeSurface(tile);
+ SDL_FreeSurface(side);
+ SDL_FreeSurface(bar);
+ SDL_FreeSurface(tee);
+ SDL_FreeSurface(bottom);
}
-theme_t *theme_init(const char *theme_name, double zoom) {
+theme_t *theme_load(const char *theme_name, double zoom) {
theme_t *res=(theme_t*)xmalloc(sizeof(theme_t));
/* file to parse for generic settings */
@@ -383,3 +388,23 @@
return res;
}
+
+void theme_free(theme_t *theme) {
+ animation_free(theme->alert_a);
+ animation_free(theme->canon_a);
+ animation_free(theme->countdown_a);
+ animation_free(theme->cup_a);
+ SDL_FreeSurface(theme->background);
+
+ int color, state;
+ for (color=0; color<NB_COLORS; color++) {
+ for (state=0; state<NB_BUBBLE_STATES; state++) {
+ Set anim=theme->bubble_a[color][state];
+ if (! (--anim->ref) )
+ animation_free(anim);
+ }
+ }
+
+ free(theme);
+}
+
Index: theme.h
===================================================================
RCS file: /cvsroot/xbubble/xbubble-sdl/src/theme.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- theme.h 11 Aug 2006 12:14:43 -0000 1.1.1.1
+++ theme.h 14 Sep 2006 12:35:41 -0000 1.2
@@ -22,6 +22,7 @@
short window_title;/* whether the windows have a title */
};
-theme_t *theme_init(const char*theme_name, double zoom);
+theme_t *theme_load(const char*theme_name, double zoom);
+void theme_free(theme_t *theme);
#endif /* H_THEME */
- Previous message: [Xbubble-commits] xbubble-sdl/src board.c, 1.7, 1.8 board.h, 1.4,
1.5 theme.c, 1.4, 1.5 xbubble.c, 1.6, 1.7
- Next message: [Xbubble-commits] xbubble-sdl/src board.c, 1.8, 1.9 board.h, 1.5,
1.6 game.c, 1.7, 1.8
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Xbubble-commits
mailing list