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

Friendly Automation asteriskteam at digium.com
Fri Jan 11 08:26:12 CST 2019


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

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
  Friendly Automation: Approved for Submit



diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 288bff1..bcd73aa 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -1068,10 +1068,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/10866
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I00811c34ae910836a5fb6d22304528aef92624db
Gerrit-Change-Number: 10866
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/50f0efab/attachment-0001.html>


More information about the asterisk-code-review mailing list