commit 04a74da695ff47620457009b90c8a59fb2f0ecbf
parent 800410a3d6773fe21dab5c539a6f973a3d2340df
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sat, 17 Jul 2021 20:25:50 -0700
Fix next command and memory leak
The next command didn't actually use the set patterns and argsub
didn't free the old argument array. Also argfree wasn't used to
free aps->next in aps_close, it is now.
Diffstat:
6 files changed, 6 insertions(+), 16 deletions(-)
diff --git a/aps/aps.c b/aps/aps.c
@@ -32,7 +32,7 @@
#include "util.h"
struct aps *
-aps_open(char *path, char **player, char **next)
+aps_open(char *path, char **player)
{
struct aps *aps;
int i;
@@ -52,11 +52,6 @@ aps_open(char *path, char **player, char **next)
return NULL;
}
- if (next && argsub(&aps->next, next, arglen(next)) == NULL) {
- aps_close(aps);
- return NULL;
- }
-
aps->con = apopen(path, bind, SOCK_NONBLOCK);
if (aps->con == NULL || listen(aps->con->sock, 10)) {
aps_close(aps);
@@ -83,9 +78,7 @@ aps_close(struct aps *aps)
aps_drop(aps, i);
apclose(aps->con);
- for (i = 0; i < arglen(aps->next); ++i)
- free(aps->next[i]);
-
+ argfree(aps->next);
free(aps);
}
diff --git a/aps/aps.h b/aps/aps.h
@@ -22,7 +22,7 @@ struct aps {
struct item *queue;
};
-struct aps *aps_open(char *, char **, char **);
+struct aps *aps_open(char *, char **);
void aps_close(struct aps *);
int aps_drop(struct aps *, int);
int aps_accept(struct aps *);
diff --git a/aps/arg.c b/aps/arg.c
@@ -76,6 +76,7 @@ argsub(char ***p, char **args, unsigned int len)
args = argdup(args, len);
if (args == NULL)
return NULL;
+ argfree(*p);
*p = args;
return args;
}
diff --git a/aps/command.c b/aps/command.c
@@ -177,7 +177,7 @@ aps_next(struct aps *aps, int s, int argc, char **argv)
return strerror(errno);
return NULL;
}
- return findplay(aps, argv, argc, 0);
+ return findplay(aps, aps->next, arglen(aps->next), 0);
}
char *
diff --git a/aps/config.h b/aps/config.h
@@ -4,8 +4,4 @@ static char *player[] = {
"ffplay", "apsplayer", "-loglevel", "error", "-nodisp", "-autoexit", "", NULL
};
-static char *next[] = {
- "1", NULL
-};
-
static int timeout = 250;
diff --git a/aps/main.c b/aps/main.c
@@ -97,7 +97,7 @@ main(int argc, char *argv[])
}
#endif
- aps = aps_open(NULL, player, next);
+ aps = aps_open(NULL, player);
if (aps == NULL) {
slog("unable to setup server");
return 1;