-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for missing memory context switch back
If memory context is switched temporarily and there is no switch back, it will cause strange errors. This adds a Coccinelle rule that checks for a case where the memory context is saved in a temporary variable but this variable is not used to switch back to the original memory context. Co-authored-by: Fabrízio de Royes Mello <fabrizio@timescale.com>
- Loading branch information
1 parent
e5b5e43
commit c07decf
Showing
2 changed files
with
27 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// find MemoryContextSwitchTo missing a context switch back | ||
@ MemoryContextSwitch @ | ||
local idexpression oldctx; | ||
position p; | ||
@@ | ||
oldctx@p = MemoryContextSwitchTo(...); | ||
|
||
@safelist@ | ||
local idexpression MemoryContextSwitch.oldctx; | ||
position MemoryContextSwitch.p; | ||
@@ | ||
oldctx@p = MemoryContextSwitchTo(...); | ||
... | ||
MemoryContextSwitchTo(oldctx) | ||
|
||
@depends on !safelist@ | ||
expression oldctx; | ||
position MemoryContextSwitch.p; | ||
@@ | ||
+ /* MemoryContextSwitch missing context switch back */ | ||
oldctx@p = MemoryContextSwitchTo(...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters