[Asterisk-code-review] vector: multiple evaluation of elem in AST VECTOR ADD SORTED. (asterisk[13])

Corey Farrell asteriskteam at digium.com
Thu Oct 5 18:00:46 CDT 2017


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/6664


Change subject: vector: multiple evaluation of elem in AST_VECTOR_ADD_SORTED.
......................................................................

vector: multiple evaluation of elem in AST_VECTOR_ADD_SORTED.

Use temporary variable to prevent multiple evaluations of elem argument.
This resolves a memory leak in res_pjproject startup.

ASTERISK-27317 #close

Change-Id: Ib960d7f5576f9e1a3c478ecb48995582a574e06d
---
M include/asterisk/vector.h
1 file changed, 3 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/64/6664/1

diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 2073bae..7d9dbe7 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -315,16 +315,17 @@
 #define AST_VECTOR_ADD_SORTED(vec, elem, cmp) ({ \
 	int res = 0; \
 	size_t __idx = (vec)->current; \
+	typeof(elem) __elem = (elem); \
 	do { \
 		if (__make_room((vec)->current, vec) != 0) { \
 			res = -1; \
 			break; \
 		} \
-		while (__idx > 0 && (cmp((vec)->elems[__idx - 1], elem) > 0)) { \
+		while (__idx > 0 && (cmp((vec)->elems[__idx - 1], __elem) > 0)) { \
 			(vec)->elems[__idx] = (vec)->elems[__idx - 1]; \
 			__idx--; \
 		} \
-		(vec)->elems[__idx] = elem; \
+		(vec)->elems[__idx] = __elem; \
 		(vec)->current++; \
 	} while (0); \
 	res; \

-- 
To view, visit https://gerrit.asterisk.org/6664
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib960d7f5576f9e1a3c478ecb48995582a574e06d
Gerrit-Change-Number: 6664
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171005/e7325a77/attachment.html>


More information about the asterisk-code-review mailing list