# Re: \[PATCH\] kprobe\_event\_gen\_test : Fix error handling and resource cleanup

- From: Luis Chamberlain \<mcgrof@kernel.org\>
- Date: 2025-09-07 01:23:05 
- List: linux-modules
- Page: https://ratatoskr.run/linux-modules/2025/09/3204763
- Thread: https://ratatoskr.run/linux-modules/2025/09/3204480/t.md

```text
On Sat, Sep 06, 2025 at 05:15:59PM +0400, Fidal Palamparambil wrote:
> From: Fidal palamparambil <redacted>
> 
> This commit addresses several issues in the kprobe event generation test module:
> 
> 1. Fixed NULL pointer management in error paths where trace_event_file pointers
>    were not properly set to NULL after errors, potentially causing double-free
>    or use-after-free issues.
> 
> 2. Added comprehensive cleanup for the kprobe event when kretprobe initialization
>    fails in kprobe_event_gen_test_init(). Previously, a failed kretprobe creation
>    would leave the kprobe event dangling.
> 
> 3. Enhanced error handling consistency between kprobe and kretprobe test functions,
>    ensuring both follow the same pattern for resource cleanup.
> 
> 4. Fixed the error handling flow in test_gen_kprobe_cmd() and test_gen_kretprobe_cmd()
>    to properly set trace_event_file pointers to NULL when errors occur after
>    event creation but before successful completion.
> 
> The changes ensure proper resource management and prevent potential memory
> corruption or leaks during module initialization and cleanup.
> 
> Signed-off-by: Fidal palamparambil <redacted>

Please just stop.

 Luis
```
