Minor optimization, use strdupa() for small alloc ops.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-04-07 10:31:59 +02:00
1 parent 2825100f77
commit d43af8c9c1
3 files changed
+3 -11

No files matched your search

+1 -3
View File
@@ -98,7 +98,7 @@ static void group_init(char *path, int leaf, const char *cfg)
if (!cfg) if (!cfg)
return; return;
s = strdup(cfg); s = strdupa(cfg);
if (!s) { if (!s) {
_pe("Failed activating cgroup cfg for %s", path); _pe("Failed activating cgroup cfg for %s", path);
return; return;
@@ -115,8 +115,6 @@ static void group_init(char *path, int leaf, const char *cfg)
ptr = strtok(NULL, ","); ptr = strtok(NULL, ",");
} }
free(s);
} }
static int cgroup_leaf_init(char *group, char *name, int pid, const char *cfg) static int cgroup_leaf_init(char *group, char *name, int pid, const char *cfg)
+1 -2
View File
@@ -364,7 +364,7 @@ static char *svc_cond(svc_t *svc, char *buf, size_t len)
if (!svc->cond[0]) if (!svc->cond[0])
return buf; return buf;
conds = strdup(svc->cond); conds = strdupa(svc->cond);
if (!conds) if (!conds)
return buf; return buf;
@@ -401,7 +401,6 @@ static char *svc_cond(svc_t *svc, char *buf, size_t len)
} }
strlcat(buf, ">", len); strlcat(buf, ">", len);
free(conds);
return buf; return buf;
} }
+1 -6
View File
@@ -1078,7 +1078,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
return errno = EINVAL; return errno = EINVAL;
} }
line = strdup(cfg); line = strdupa(cfg);
if (!line) if (!line)
return 1; return 1;
@@ -1104,7 +1104,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
if (!cmd) { if (!cmd) {
incomplete: incomplete:
_e("Incomplete service '%s', cannot register", cfg); _e("Incomplete service '%s', cannot register", cfg);
free(line);
return errno = ENOENT; return errno = ENOENT;
} }
@@ -1147,7 +1146,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
levels = conf_parse_runlevels(runlevels); levels = conf_parse_runlevels(runlevels);
if (runlevel > 0 && !ISOTHER(levels, 0)) { if (runlevel > 0 && !ISOTHER(levels, 0)) {
_d("Skipping %s, bootstrap is completed.", cmd); _d("Skipping %s, bootstrap is completed.", cmd);
free(line);
return 0; return 0;
} }
@@ -1160,7 +1158,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
svc = svc_new(cmd, id, type); svc = svc_new(cmd, id, type);
if (!svc) { if (!svc) {
_e("Out of memory, cannot register service %s", cmd); _e("Out of memory, cannot register service %s", cmd);
free(line);
return errno = ENOMEM; return errno = ENOMEM;
} }
@@ -1231,8 +1228,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
if (!file) if (!file)
svc->protect = 1; svc->protect = 1;
/* Free duped line, from above */
free(line);
return 0; return 0;
} }