char*
gen_inprogress_lock (int game, pid_t pid, char* ttyrec_filename)
{
- char *lockfile = NULL, filebuf[80];
+ char *lockfile = NULL, *inprogdir = NULL, filebuf[80];
int fd;
size_t len, wrlen;
struct flock fl = { 0 };
fl.l_start = 0;
fl.l_len = 0;
- len = strlen(dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL)) + strlen(me->username) + strlen(ttyrec_filename) + 13;
+ len = strlen(inprogdir = dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL)) + strlen(me->username) + strlen(ttyrec_filename) + 13;
lockfile = calloc(len, sizeof(char));
- snprintf (lockfile, len, "%s%s:%s", dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL),
+ snprintf (lockfile, len, "%s%s:%s", inprogdir,
me->username, ttyrec_filename);
+ free(inprogdir);
fd = open (lockfile, O_WRONLY | O_CREAT, 0644);
if (fcntl (fd, F_SETLKW, &fl) == -1) {
dgl_exec_cmdqueue_w(myconfig[gnum]->watchcmdqueue, gnum, me, chosen_name);
/* fix the variables in the arguments */
for (i = 0; i < myconfig[gnum]->num_wargs; i++) {
- wargs[i] = strdup(dgl_format_str(gnum, me, myconfig[gnum]->watch_args[i], chosen_name));
+ wargs[i] = dgl_format_str(gnum, me, myconfig[gnum]->watch_args[i], chosen_name);
}
wargs[myconfig[gnum]->num_wargs] = NULL;
/* tidy up signals before launching external process */
size_t len;
short firsttime = 1;
- dir = strdup(dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL));
+ dir = dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL);
if (!(pdir = opendir (dir))) {
debug_write("purge_stale_locks dir open failed");
while ((dent = readdir (pdir)) != NULL)
{
FILE *ipfile;
- char *colon, *fn;
+ char *colon, *fn, *inprogdir = NULL;
char buf[16];
pid_t pid;
size_t len;
if (strncmp (dent->d_name, me->username, colon - dent->d_name))
continue;
- len = strlen (dent->d_name) + strlen(dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL)) + 1;
+ len = strlen (dent->d_name) + strlen(inprogdir = dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL)) + 1;
fn = malloc (len);
- snprintf (fn, len, "%s%s", dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL), dent->d_name);
+ snprintf (fn, len, "%s%s", inprogdir, dent->d_name);
+ free(inprogdir);
if (!(ipfile = fopen (fn, "r"))) {
debug_write("purge_stale_locks fopen inprogressdir fail");
char *
dgl_format_str(int game, struct dg_user *me, char *str, char *plrname)
{
- static char buf[1024];
+ char buf[1024];
char *f, *p, *end, *varname = NULL, *fallback = NULL;
int ispercent = 0;
int isbackslash = 0;
}
*p = '\0';
- return buf;
+ return strdup(buf);
}
int
if (!queue) return 1;
- p1 = (char *)malloc(1024);
- p2 = (char *)malloc(1024);
-
- if (!p1 || !p2) return 1;
-
return_from_submenu = 0;
while (tmp && !return_from_submenu) {
- if (tmp->param1) strcpy(p1, dgl_format_str(game, me, tmp->param1, playername));
- if (tmp->param2) strcpy(p2, dgl_format_str(game, me, tmp->param2, playername));
+ if (tmp->param1) p1 = dgl_format_str(game, me, tmp->param1, playername);
+ if (tmp->param2) p2 = dgl_format_str(game, me, tmp->param2, playername);
switch (tmp->cmd) {
default: break;
case DGLCMD_SETPREFPATH:
if (loggedin && p1) {
free(userpref_path);
- userpref_path = strdup(dgl_format_str(-1, me, p1, playername));
+ userpref_path = dgl_format_str(-1, me, p1, playername);
}
break;
case DGLCMD_SETPREF:
for (userchoice = 0; userchoice < num_games; userchoice++) {
if (!strcmp(myconfig[userchoice]->game_id, p1) || !strcmp(myconfig[userchoice]->game_name, p1) || !strcmp(myconfig[userchoice]->shortname, p1)) {
if (purge_stale_locks(userchoice)) {
+ char *ttrecdir = NULL
if (myconfig[userchoice]->rcfile) {
- if (access (dgl_format_str(userchoice, me, myconfig[userchoice]->rc_fmt, NULL), R_OK) == -1)
- write_canned_rcfile (userchoice, dgl_format_str(userchoice, me, myconfig[userchoice]->rc_fmt, NULL));
+ char *rcname = NULL;
+ if (access (rcname = dgl_format_str(userchoice, me, myconfig[userchoice]->rc_fmt, NULL), R_OK) == -1)
+ write_canned_rcfile (userchoice, rcname);
+ if (rcname) free(rcname);
}
setproctitle("%s [playing %s]", me->username, myconfig[userchoice]->shortname);
/* fix the variables in the arguments */
for (i = 0; i < myconfig[userchoice]->num_args; i++) {
- tmpstr = strdup(dgl_format_str(userchoice, me, myconfig[userchoice]->bin_args[i], NULL));
+ tmpstr = dgl_format_str(userchoice, me, myconfig[userchoice]->bin_args[i], NULL);
free(myconfig[userchoice]->bin_args[i]);
myconfig[userchoice]->bin_args[i] = tmpstr;
}
idle_alarm_set_enabled(0);
/* launch program */
ttyrec_main (userchoice, me->username,
- dgl_format_str(userchoice, me, myconfig[userchoice]->ttyrecdir, NULL),
+ ttrecdir = dgl_format_str(userchoice, me, myconfig[userchoice]->ttyrecdir, NULL),
gen_ttyrec_filename());
idle_alarm_set_enabled(1);
played = 1;
+ if (ttrecdir) free(ttrecdir);
/* lastly, run the generic "do these when a game is left" commands */
signal (SIGHUP, catch_sighup);
signal (SIGINT, catch_sighup);
break;
}
tmp = tmp->next;
+ if (p1) free(p1);
+ if (p2) free(p2);
}
-
- free(p1);
- free(p2);
-
return 0;
}
for (game = ((xgame < 0) ? 0 : xgame); game < ((xgame <= 0) ? num_games : (xgame+1)); game++) {
- dir = strdup(dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL));
+ dir = dgl_format_str(game, me, myconfig[game]->inprogressdir, NULL);
if (!dir) continue;
if (!(pdir = opendir (dir))) {
debug_write("cannot open inprogress-dir");
graceful_exit (140);
}
+ free(dir);
while ((pdirent = readdir (pdir)))
{
if (!inprog) continue;
snprintf (fullname, 130, "%s%s", inprog, pdirent->d_name);
+ free(inprog);
fd = 0;
/* O_RDWR here should be O_RDONLY, but we need to test for
ttrecdir = dgl_format_str(game, NULL, myconfig[game]->ttyrecdir, playername);
if (!ttrecdir) continue;
snprintf (ttyrecname, 130, "%s%s", ttrecdir, replacestr);
+ free(ttrecdir);
if (!stat (ttyrecname, &pstat))
{
myconfig[game]->extra_info_file,
games[len]->name);
game_read_extra_info(games[len], extra_info_file);
+ free(extra_info_file);
}
len++;