Skip to content

Commit 5e6ded2

Browse files
Tom Rixpmladek
Tom Rix
authored andcommitted
livepatch: Reorder to use before freeing a pointer
Clang static analysis reports this issue livepatch-shadow-fix1.c:113:2: warning: Use of memory after it is freed pr_info("%s: dummy @ %p, prevented leak @ %p\n", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The pointer is freed in the previous statement. Reorder the pr_info to report before the free. Similar issue in livepatch-shadow-fix2.c Note that it is a false positive. pr_info() just prints the address. The freed memory is not accessed. Well, the static analyzer could not know this easily. Signed-off-by: Tom Rix <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Acked-by: David Vernet <[email protected]> Acked-by: Joe Lawrence <[email protected]> [[email protected]: Note about that it was false positive.] Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4327b9e commit 5e6ded2

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

samples/livepatch/livepatch-shadow-fix1.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
109109
void *d = obj;
110110
int **shadow_leak = shadow_data;
111111

112-
kfree(*shadow_leak);
113112
pr_info("%s: dummy @ %p, prevented leak @ %p\n",
114113
__func__, d, *shadow_leak);
114+
kfree(*shadow_leak);
115115
}
116116

117117
static void livepatch_fix1_dummy_free(struct dummy *d)

samples/livepatch/livepatch-shadow-fix2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
6161
void *d = obj;
6262
int **shadow_leak = shadow_data;
6363

64-
kfree(*shadow_leak);
6564
pr_info("%s: dummy @ %p, prevented leak @ %p\n",
6665
__func__, d, *shadow_leak);
66+
kfree(*shadow_leak);
6767
}
6868

6969
static void livepatch_fix2_dummy_free(struct dummy *d)

0 commit comments

Comments
 (0)