Skip to content

Commit

Permalink
PM: hibernate: Fix potential memory leak in hibernate_preallocate_mem…
Browse files Browse the repository at this point in the history
…ory() and prepare_highmem_image()

hibernate_preallocate_memory() and prepare_highmem_image() allocates
memory chunk with memory_bm_create(). When the function gets some error
after memory_bm_create(), relavent memory should be released with
memory_bm_free().

Fix it by calling memory_bm_free() at the right time.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
  • Loading branch information
Jianglei Nie authored and intel-lab-lkp committed Sep 5, 2022
1 parent 7e18e42 commit e7861e5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kernel/power/snapshot.c
Expand Up @@ -1752,6 +1752,7 @@ int hibernate_preallocate_memory(void)

error = memory_bm_create(&copy_bm, GFP_IMAGE, PG_ANY);
if (error) {
memory_bm_free(orig_bm, PG_UNSAFE_CLEAR);
pr_err("Cannot allocate copy bitmap\n");
goto err_out;
}
Expand Down Expand Up @@ -2335,8 +2336,10 @@ static int prepare_highmem_image(struct memory_bitmap *bm,
if (memory_bm_create(bm, GFP_ATOMIC, PG_SAFE))
return -ENOMEM;

if (get_highmem_buffer(PG_SAFE))
if (get_highmem_buffer(PG_SAFE)) {
memory_bm_free(bm, PG_UNSAFE_CLEAR);
return -ENOMEM;
}

to_alloc = count_free_highmem_pages();
if (to_alloc > *nr_highmem_p)
Expand Down

0 comments on commit e7861e5

Please sign in to comment.