[Asterisk-code-review] RAII: Change order or variables in clang version (asterisk[master])

Friendly Automation asteriskteam at digium.com
Fri Jan 11 08:28:40 CST 2019


Friendly Automation has submitted this change and it was merged. ( https://gerrit.asterisk.org/10854 )

Change subject: RAII: Change order or variables in clang version
......................................................................

RAII: Change order or variables in clang version

This prevents use-after-scope issues when unwinding the stack,
which happens in reverse order. The varname variable needs to
remain alive for the destruction to be able to access it.
Issue was found using clang + address-sanitizer.

ASTERISK-28232 #close

Change-Id: I00811c34ae910836a5fb6d22304528aef92624db
---
M include/asterisk/utils.h
1 file changed, 4 insertions(+), 4 deletions(-)

Approvals:
  Joshua C. Colp: Looks good to me, approved; Verified
  Corey Farrell: Looks good to me, but someone else must approve
  Friendly Automation: Approved for Submit



diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index c0cce98..4dc406d 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -786,10 +786,10 @@
 typedef void (^_raii_cleanup_block_t)(void);
 static inline void _raii_cleanup_block(_raii_cleanup_block_t *b) { (*b)(); }
 
-#define RAII_VAR(vartype, varname, initval, dtor)                                                                \
-    _raii_cleanup_block_t _raii_cleanup_ ## varname __attribute__((cleanup(_raii_cleanup_block),unused)) = NULL; \
-    __block vartype varname = initval;                                                                           \
-    _raii_cleanup_ ## varname = ^{ {(void)dtor(varname);} }
+#define RAII_VAR(vartype, varname, initval, dtor)                                                              \
+    __block vartype varname = initval;                                                                         \
+    _raii_cleanup_block_t _raii_cleanup_ ## varname __attribute__((cleanup(_raii_cleanup_block),unused)) =     \
+        ^{ {(void)dtor(varname);} };
 
 #elif defined(__GNUC__)
 

-- 
To view, visit https://gerrit.asterisk.org/10854
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I00811c34ae910836a5fb6d22304528aef92624db
Gerrit-Change-Number: 10854
Gerrit-PatchSet: 3
Gerrit-Owner: Diederik de Groot <dkgroot at talon.nl>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Diederik de Groot <dkgroot at talon.nl>
Gerrit-Reviewer: Friendly Automation (1000185)
Gerrit-Reviewer: Joshua C. Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190111/2c067bf9/attachment-0001.html>


More information about the asterisk-code-review mailing list