1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-06-02 10:18:44 +02:00

Cleanup: remove unnecessary allocations

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
David Oberhollenzer 2018-04-08 18:04:01 +02:00
parent 6b788edfa4
commit a42022c650

View file

@ -273,8 +273,6 @@ static int splitkv(const char *filename, size_t lineno,
{ {
char *key = line, *value = line; char *key = line, *value = line;
*k = *v = NULL;
while (*value != ' ' && *value != '\0') { while (*value != ' ' && *value != '\0') {
if (!isalpha(*value)) { if (!isalpha(*value)) {
fprintf(stderr, fprintf(stderr,
@ -293,12 +291,6 @@ static int splitkv(const char *filename, size_t lineno,
*(value++) = '\0'; *(value++) = '\0';
value = strdup(value);
if (value == NULL) {
fprintf(stderr, "%s: %zu: out of memory\n", filename, lineno);
return -1;
}
*k = key; *k = key;
*v = value; *v = value;
return 0; 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) 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 struct svc_param *p;
const char *arg, *args[1]; const char *arg, *args[1];
service_t *svc = NULL; service_t *svc = NULL;
@ -368,10 +360,12 @@ service_t *rdsvc(int dirfd, const char *filename)
goto fail; goto fail;
p = find_param(filename, lineno, key); p = find_param(filename, lineno, key);
if (p == NULL || p->handle(svc, value, filename, lineno) != 0) if (p == NULL)
goto fail; goto fail;
free(line); memmove(line, value, strlen(value) + 1);
if (p->handle(svc, line, filename, lineno))
goto fail;
} }
close(fd); close(fd);
@ -379,7 +373,6 @@ service_t *rdsvc(int dirfd, const char *filename)
fail_oom: fail_oom:
fputs("out of memory\n", stderr); fputs("out of memory\n", stderr);
fail: fail:
free(value);
free(line); free(line);
delsvc(svc); delsvc(svc);
close(fd); close(fd);