jenkins-bot has submitted this change and it was merged. Change subject: Plug leaks on error paths. ......................................................................
Plug leaks on error paths. Found with 'make test' on a --enable-debug php build (which does leak checking). Change-Id: If231d7a1ee126fad8e4f9ca818b243750c32cf2b --- M data_conversion.c M luasandbox.c 2 files changed, 13 insertions(+), 7 deletions(-) Approvals: Tim Starling: Looks good to me, but someone else must approve Anomie: Looks good to me, approved Cscott: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/data_conversion.c b/data_conversion.c index be7af4e..1ed6925 100644 --- a/data_conversion.c +++ b/data_conversion.c @@ -262,7 +262,7 @@ MAKE_STD_ZVAL(zex); object_init_ex(zex, luasandboxruntimeerror_ce); - MAKE_STD_ZVAL(ztrace); + ALLOC_INIT_ZVAL(ztrace); // IS_NULL if lua_to_zval fails. luasandbox_push_structured_trace(L, 1); luasandbox_lua_to_zval(ztrace, L, -1, sandbox_zval, NULL TSRMLS_CC); zend_update_property(luasandboxruntimeerror_ce, zex, "luaTrace", sizeof("luaTrace")-1, ztrace TSRMLS_CC); @@ -297,6 +297,9 @@ } if (!success) { + // free the array created by array_init() above. + zval_dtor(z); + ZVAL_NULL(z); return 0; } break; @@ -351,7 +354,7 @@ MAKE_STD_ZVAL(zex); object_init_ex(zex, luasandboxruntimeerror_ce); - MAKE_STD_ZVAL(ztrace); + ALLOC_INIT_ZVAL(ztrace); // IS_NULL if lua_to_zval fails. luasandbox_push_structured_trace(L, 1); luasandbox_lua_to_zval(ztrace, L, -1, sandbox_zval, NULL TSRMLS_CC); zend_update_property(luasandboxruntimeerror_ce, zex, "luaTrace", sizeof("luaTrace")-1, ztrace TSRMLS_CC); @@ -393,9 +396,10 @@ lua_pushnil(L); while (lua_next(L, index) != 0) { - MAKE_STD_ZVAL(value); + ALLOC_INIT_ZVAL(value); // ensure is inited even if lua_to_zval bails. if (!luasandbox_lua_to_zval(value, L, -1, sandbox_zval, recursionGuard TSRMLS_CC)) { // Conversion failed, fix stack and bail + zval_ptr_dtor(&value); lua_settop(L, top); return 0; } diff --git a/luasandbox.c b/luasandbox.c index 50ea359..c7fc7fc 100644 --- a/luasandbox.c +++ b/luasandbox.c @@ -717,7 +717,7 @@ // Push the trace on to the top of the stack lua_rawgeti(L, -1, 3); // Convert it to a zval - MAKE_STD_ZVAL(ztrace); + ALLOC_INIT_ZVAL(ztrace); // IS_NULL if lua_to_zval fails. luasandbox_lua_to_zval(ztrace, L, -1, sandbox->current_zval, NULL TSRMLS_CC); // Put it in the exception object zend_update_property(ce, zex, "luaTrace", sizeof("luaTrace")-1, ztrace TSRMLS_CC); @@ -1376,9 +1376,10 @@ // Fill the array with the results for (i = 0; i < numResults; i++) { zval * element; - MAKE_STD_ZVAL(element); + ALLOC_INIT_ZVAL(element); // ensure elem is inited in case we bail if (!luasandbox_lua_to_zval(element, L, retIndex + i, sandbox_zval, NULL TSRMLS_CC)) { // Convert failed (which means an exception), so bail. + zval_ptr_dtor(&element); break; } zend_hash_next_index_insert(Z_ARRVAL_P(return_value), @@ -1592,10 +1593,11 @@ double_pointers = (zval***)temp; pointers = (zval**)(temp + top); for (i = 0; i < top; i++ ) { - MAKE_STD_ZVAL(pointers[i]); + ALLOC_INIT_ZVAL(pointers[i]); // ensure is inited in case we fail if (!luasandbox_lua_to_zval(pointers[i], L, i + 1, intern->current_zval, NULL TSRMLS_CC)) { // Argument conversion failed, so skip the call. The PHP exception - // from the conversion will be handled below. + // from the conversion will be handled below, along with freeing + // all the zvals in pointers[0 <= i < top]. args_failed = 1; top = i + 1; break; -- To view, visit https://gerrit.wikimedia.org/r/97931 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If231d7a1ee126fad8e4f9ca818b243750c32cf2b Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/php/luasandbox Gerrit-Branch: master Gerrit-Owner: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Cscott <canan...@wikimedia.org> Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits