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

Joshua C. Colp asteriskteam at digium.com
Fri Jan 11 08:28:20 CST 2019


Joshua C. Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/10868 )

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:
  Corey Farrell: Looks good to me, but someone else must approve
  Joshua C. Colp: Looks good to me, approved; 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/10868
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: merged
Gerrit-Change-Id: I00811c34ae910836a5fb6d22304528aef92624db
Gerrit-Change-Number: 10868
Gerrit-PatchSet: 1
Gerrit-Owner: Diederik de Groot <dkgroot at talon.nl>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
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/b0c2fdc4/attachment.html>


More information about the asterisk-code-review mailing list