mirror of
https://github.com/troglobit/finit.git
synced 2026-10-08 00:24:17 +07:00
Minor optimization, use strdupa() for small alloc ops.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+1
-3
@@ -98,7 +98,7 @@ static void group_init(char *path, int leaf, const char *cfg)
|
||||
if (!cfg)
|
||||
return;
|
||||
|
||||
s = strdup(cfg);
|
||||
s = strdupa(cfg);
|
||||
if (!s) {
|
||||
_pe("Failed activating cgroup cfg for %s", path);
|
||||
return;
|
||||
@@ -115,8 +115,6 @@ static void group_init(char *path, int leaf, const char *cfg)
|
||||
|
||||
ptr = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
free(s);
|
||||
}
|
||||
|
||||
static int cgroup_leaf_init(char *group, char *name, int pid, const char *cfg)
|
||||
|
||||
+1
-2
@@ -364,7 +364,7 @@ static char *svc_cond(svc_t *svc, char *buf, size_t len)
|
||||
if (!svc->cond[0])
|
||||
return buf;
|
||||
|
||||
conds = strdup(svc->cond);
|
||||
conds = strdupa(svc->cond);
|
||||
if (!conds)
|
||||
return buf;
|
||||
|
||||
@@ -401,7 +401,6 @@ static char *svc_cond(svc_t *svc, char *buf, size_t len)
|
||||
}
|
||||
|
||||
strlcat(buf, ">", len);
|
||||
free(conds);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
+1
-6
@@ -1078,7 +1078,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
return errno = EINVAL;
|
||||
}
|
||||
|
||||
line = strdup(cfg);
|
||||
line = strdupa(cfg);
|
||||
if (!line)
|
||||
return 1;
|
||||
|
||||
@@ -1104,7 +1104,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
if (!cmd) {
|
||||
incomplete:
|
||||
_e("Incomplete service '%s', cannot register", cfg);
|
||||
free(line);
|
||||
return errno = ENOENT;
|
||||
}
|
||||
|
||||
@@ -1147,7 +1146,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
levels = conf_parse_runlevels(runlevels);
|
||||
if (runlevel > 0 && !ISOTHER(levels, 0)) {
|
||||
_d("Skipping %s, bootstrap is completed.", cmd);
|
||||
free(line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1160,7 +1158,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
svc = svc_new(cmd, id, type);
|
||||
if (!svc) {
|
||||
_e("Out of memory, cannot register service %s", cmd);
|
||||
free(line);
|
||||
return errno = ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1231,8 +1228,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
if (!file)
|
||||
svc->protect = 1;
|
||||
|
||||
/* Free duped line, from above */
|
||||
free(line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user