aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-04-08 18:04:01 +0200
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-04-08 18:04:01 +0200
commita42022c6505ba278dcc6b6ea8f790e37f8924cca (patch)
treedc669f3fa8850849251b2a1c80d9001f4b6883c8
parent6b788edfa40fd9c006f071ce764677e9dd2f9384 (diff)
Cleanup: remove unnecessary allocations
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
-rw-r--r--lib/src/rdsvc.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/lib/src/rdsvc.c b/lib/src/rdsvc.c
index 8e9603d..29c9019 100644
--- a/lib/src/rdsvc.c
+++ b/lib/src/rdsvc.c
@@ -273,8 +273,6 @@ static int splitkv(const char *filename, size_t lineno,
{
char *key = line, *value = line;
- *k = *v = NULL;
-
while (*value != ' ' && *value != '\0') {
if (!isalpha(*value)) {
fprintf(stderr,
@@ -293,12 +291,6 @@ static int splitkv(const char *filename, size_t lineno,
*(value++) = '\0';
- value = strdup(value);
- if (value == NULL) {
- fprintf(stderr, "%s: %zu: out of memory\n", filename, lineno);
- return -1;
- }
-
*k = key;
*v = value;
return 0;
@@ -322,7 +314,7 @@ static const struct svc_param *find_param(const char *filename, size_t lineno,
service_t *rdsvc(int dirfd, const char *filename)
{
- char *line = NULL, *key, *value = NULL;
+ char *line = NULL, *key, *value;
const struct svc_param *p;
const char *arg, *args[1];
service_t *svc = NULL;
@@ -368,10 +360,12 @@ service_t *rdsvc(int dirfd, const char *filename)
goto fail;
p = find_param(filename, lineno, key);
- if (p == NULL || p->handle(svc, value, filename, lineno) != 0)
+ if (p == NULL)
goto fail;
- free(line);
+ memmove(line, value, strlen(value) + 1);
+ if (p->handle(svc, line, filename, lineno))
+ goto fail;
}
close(fd);
@@ -379,7 +373,6 @@ service_t *rdsvc(int dirfd, const char *filename)
fail_oom:
fputs("out of memory\n", stderr);
fail:
- free(value);
free(line);
delsvc(svc);
close(fd);