Free populated games.

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@476 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Pasi Kallinen 2009-10-18 08:39:19 +00:00
parent fff23611d8
commit c08ce22995
3 changed files with 27 additions and 4 deletions

View File

@ -375,7 +375,7 @@ inprogressmenu (int gameid)
int i, menuchoice, len = 20, offset = 0, doresizewin = 0;
static dg_sortmode sortmode = NUM_SORTMODES;
time_t ctime;
struct dg_game **games;
struct dg_game **games = NULL;
char ttyrecname[130], *replacestr = NULL, gametype[10];
int *is_nhext;
sigset_t oldmask, toblock;
@ -405,7 +405,7 @@ inprogressmenu (int gameid)
max_height = local_LINES - 10;
if (max_height < 2) {
free(is_nhext);
/* TODO: free games[] */
free_populated_games(games, len);
return;
}
if (max_height > abs_max_height) max_height = abs_max_height;
@ -507,6 +507,7 @@ inprogressmenu (int gameid)
case ERR:
case 'q': case 'Q':
if (is_nhext) free(is_nhext);
free_populated_games(games, len);
return;
case '.':
@ -597,6 +598,7 @@ watchgame:
games = sort_games (games, len, sortmode);
}
if (is_nhext) free(is_nhext);
free_populated_games(games, len);
}
/* ************************************************************* */
@ -769,7 +771,7 @@ void
wall_email(char *from, char *msg)
{
int len, i;
struct dg_game **games;
struct dg_game **games = NULL;
char spool_fn[1024+1];
FILE *user_spool = NULL;
struct flock fl = { 0 };
@ -817,6 +819,7 @@ wall_email(char *from, char *msg)
fprintf(user_spool, "%s:%s\n", from, msg);
fclose(user_spool);
}
free_populated_games(games, len);
}
void
@ -1874,7 +1877,7 @@ authenticate ()
{
int i, len, me_index;
char user_buf[22], pw_buf[22];
struct dg_game **games;
struct dg_game **games = NULL;
/* We use simple password authentication, rather than challenge/response. */
printf ("\n");
@ -1911,10 +1914,12 @@ authenticate ()
if (!strcmp (games[i]->name, user_buf))
{
fprintf (stderr, "Game already in progress.\n");
free_populated_games(games, len);
return 1;
}
win.ws_row = win.ws_col = 0;
gen_inprogress_lock (0, getppid (), gen_nhext_filename ());
free_populated_games(games, len);
return 0;
}
}
@ -1922,6 +1927,7 @@ authenticate ()
sleep (2);
fprintf (stderr, "Login failed.\n");
free_populated_games(games, len);
return 1;
}

View File

@ -195,6 +195,7 @@ extern struct dg_menu *dgl_find_menu(char *menuname);
extern int dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me);
extern void free_populated_games(struct dg_game **games, int len);
extern struct dg_game **populate_games(int game, int *l, struct dg_user *me);
#ifdef USE_DEBUGFILE

View File

@ -403,6 +403,22 @@ debug_write(char *str)
}
#endif /* USE_DEBUGFILE */
void
free_populated_games(struct dg_game **games, int len)
{
int i;
if (!games || (len < 1)) return;
for (i = 0; i < len; i++) {
if (games[i]->ttyrec_fn) free(games[i]->ttyrec_fn);
if (games[i]->name) free(games[i]->name);
if (games[i]->date) free(games[i]->date);
if (games[i]->time) free(games[i]->time);
free(games[i]);
}
free(games);
}
struct dg_game **
populate_games (int xgame, int *l, struct dg_user *me)
{