chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
json: fix a mem leak
[elogind.git]
/
src
/
shared
/
cgroup-util.c
diff --git
a/src/shared/cgroup-util.c
b/src/shared/cgroup-util.c
index 2654efa1ceb279ac24c0beb124df534a6fdee4ac..78270b3fa93116bc1697166540d9b070196350f5 100644
(file)
--- a/
src/shared/cgroup-util.c
+++ b/
src/shared/cgroup-util.c
@@
-1153,7
+1153,7
@@
int cg_path_decode_unit(const char *cgroup, char **unit){
c = strndupa(cgroup, n);
c = cg_unescape(c);
c = strndupa(cgroup, n);
c = cg_unescape(c);
- if (!unit_name_is_valid(c,
TEMPLATE_INVALID
))
+ if (!unit_name_is_valid(c,
UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE
))
return -ENXIO;
s = strdup(c);
return -ENXIO;
s = strdup(c);
@@
-1180,7
+1180,7
@@
static bool valid_slice_name(const char *p, size_t n) {
c = cg_unescape(buf);
c = cg_unescape(buf);
- return unit_name_is_valid(c,
TEMPLATE_INVALID
);
+ return unit_name_is_valid(c,
UNIT_NAME_PLAIN
);
}
return false;
}
return false;
@@
-1637,28
+1637,41
@@
bool cg_controller_is_valid(const char *p, bool allow_named) {
int cg_slice_to_path(const char *unit, char **ret) {
_cleanup_free_ char *p = NULL, *s = NULL, *e = NULL;
const char *dash;
int cg_slice_to_path(const char *unit, char **ret) {
_cleanup_free_ char *p = NULL, *s = NULL, *e = NULL;
const char *dash;
+ int r;
assert(unit);
assert(ret);
assert(unit);
assert(ret);
- if (!unit_name_is_valid(unit, TEMPLATE_INVALID))
+ if (streq(unit, "-.slice")) {
+ char *x;
+
+ x = strdup("");
+ if (!x)
+ return -ENOMEM;
+ *ret = x;
+ return 0;
+ }
+
+ if (!unit_name_is_valid(unit, UNIT_NAME_PLAIN))
return -EINVAL;
if (!endswith(unit, ".slice"))
return -EINVAL;
return -EINVAL;
if (!endswith(unit, ".slice"))
return -EINVAL;
-
p = unit_name_to_prefix(unit
);
- if (
!p
)
- return
-ENOMEM
;
+
r = unit_name_to_prefix(unit, &p
);
+ if (
r < 0
)
+ return
r
;
dash = strchr(p, '-');
while (dash) {
_cleanup_free_ char *escaped = NULL;
char n[dash - p + sizeof(".slice")];
dash = strchr(p, '-');
while (dash) {
_cleanup_free_ char *escaped = NULL;
char n[dash - p + sizeof(".slice")];
- strcpy(stpncpy(n, p, dash - p), ".slice");
+ if (isempty(dash + 1))
+ return -EINVAL;
- if (!unit_name_is_valid(n, TEMPLATE_INVALID))
+ strcpy(stpncpy(n, p, dash - p), ".slice");
+ if (!unit_name_is_valid(n, UNIT_NAME_PLAIN))
return -EINVAL;
escaped = cg_escape(n);
return -EINVAL;
escaped = cg_escape(n);