VECTOR: Passing parameters with side effects to macros is dangerous.

* Fix several instances where we were bumping a ref in the parameter and
then unrefing the object if it failed.  The way the AST_VECTOR_APPEND()
and AST_VECTOR_REPLACE() macros are implemented means if it fails the new
value was never evaluated.

Change-Id: I2847872a455b11ea7e5b7ce697c0a455a1d0ac9a
This commit is contained in:
Richard Mudgett
2018-06-21 16:39:45 -05:00
parent d87631d21f
commit cad50d6dbf
5 changed files with 15 additions and 7 deletions

View File

@@ -1133,7 +1133,8 @@ static struct vector_history_t *filter_history(struct ast_cli_args *a)
} else if (!res) {
continue;
} else {
if (AST_VECTOR_APPEND(output, ao2_bump(entry))) {
ao2_bump(entry);
if (AST_VECTOR_APPEND(output, entry)) {
ao2_cleanup(entry);
}
}