mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
Merge pull request #18930 from anitazha/oomdfixleak
oomd: fix memory leak
This commit is contained in:
commit
1d2e9c48e5
@ -112,7 +112,7 @@ static int process_managed_oom_reply(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = oomd_insert_cgroup_context(NULL, monitor_hm, empty_to_root(reply.path));
|
ret = oomd_insert_cgroup_context(NULL, monitor_hm, reply.path);
|
||||||
if (ret == -ENOMEM) {
|
if (ret == -ENOMEM) {
|
||||||
r = ret;
|
r = ret;
|
||||||
goto finish;
|
goto finish;
|
||||||
|
@ -384,16 +384,20 @@ int oomd_system_context_acquire(const char *proc_swaps_path, OomdSystemContext *
|
|||||||
|
|
||||||
int oomd_insert_cgroup_context(Hashmap *old_h, Hashmap *new_h, const char *path) {
|
int oomd_insert_cgroup_context(Hashmap *old_h, Hashmap *new_h, const char *path) {
|
||||||
_cleanup_(oomd_cgroup_context_freep) OomdCGroupContext *curr_ctx = NULL;
|
_cleanup_(oomd_cgroup_context_freep) OomdCGroupContext *curr_ctx = NULL;
|
||||||
OomdCGroupContext *old_ctx, *ctx;
|
OomdCGroupContext *old_ctx;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(new_h);
|
assert(new_h);
|
||||||
assert(path);
|
assert(path);
|
||||||
|
|
||||||
|
path = empty_to_root(path);
|
||||||
|
|
||||||
r = oomd_cgroup_context_acquire(path, &curr_ctx);
|
r = oomd_cgroup_context_acquire(path, &curr_ctx);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_debug_errno(r, "Failed to get OomdCGroupContext for %s: %m", path);
|
return log_debug_errno(r, "Failed to get OomdCGroupContext for %s: %m", path);
|
||||||
|
|
||||||
|
assert_se(streq(path, curr_ctx->path));
|
||||||
|
|
||||||
old_ctx = hashmap_get(old_h, path);
|
old_ctx = hashmap_get(old_h, path);
|
||||||
if (old_ctx) {
|
if (old_ctx) {
|
||||||
curr_ctx->last_pgscan = old_ctx->pgscan;
|
curr_ctx->last_pgscan = old_ctx->pgscan;
|
||||||
@ -401,11 +405,11 @@ int oomd_insert_cgroup_context(Hashmap *old_h, Hashmap *new_h, const char *path)
|
|||||||
curr_ctx->last_hit_mem_pressure_limit = old_ctx->last_hit_mem_pressure_limit;
|
curr_ctx->last_hit_mem_pressure_limit = old_ctx->last_hit_mem_pressure_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = TAKE_PTR(curr_ctx);
|
r = hashmap_put(new_h, curr_ctx->path, curr_ctx);
|
||||||
r = hashmap_put(new_h, ctx->path, ctx);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
TAKE_PTR(curr_ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +150,7 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) {
|
|||||||
assert_se(oomd_insert_cgroup_context(NULL, h1, cgroup) == 0);
|
assert_se(oomd_insert_cgroup_context(NULL, h1, cgroup) == 0);
|
||||||
c1 = hashmap_get(h1, cgroup);
|
c1 = hashmap_get(h1, cgroup);
|
||||||
assert_se(c1);
|
assert_se(c1);
|
||||||
|
assert_se(oomd_insert_cgroup_context(NULL, h1, cgroup) == -EEXIST);
|
||||||
|
|
||||||
/* make sure certain values from h1 get updated in h2 */
|
/* make sure certain values from h1 get updated in h2 */
|
||||||
c1->pgscan = 5555;
|
c1->pgscan = 5555;
|
||||||
|
Loading…
Reference in New Issue
Block a user