]> granicus.if.org Git - php/commitdiff
Avoid useless checks, using zend_string_efree(), in cases where the string is known...
authorDmitry Stogov <dmitry@zend.com>
Tue, 8 May 2018 14:30:15 +0000 (17:30 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 8 May 2018 14:30:15 +0000 (17:30 +0300)
36 files changed:
Zend/zend_API.c
Zend/zend_compile.c
Zend/zend_constants.c
Zend/zend_inheritance.c
Zend/zend_language_scanner.c
Zend/zend_language_scanner.l
Zend/zend_string.h
ext/bz2/bz2.c
ext/date/php_date.c
ext/iconv/iconv.c
ext/intl/converter/converter.c
ext/intl/idn/idn.c
ext/intl/intl_convert.c
ext/intl/locale/locale_methods.c
ext/intl/uchar/uchar.c
ext/odbc/php_odbc.c
ext/pgsql/pgsql.c
ext/reflection/php_reflection.c
ext/sockets/sockets.c
ext/sodium/libsodium.c
ext/standard/base64.c
ext/standard/basic_functions.c
ext/standard/file.c
ext/standard/html.c
ext/standard/info.c
ext/standard/iptc.c
ext/standard/net.c
ext/standard/password.c
ext/standard/streamsfuncs.c
ext/standard/string.c
ext/standard/uuencode.c
ext/standard/var_unserializer.c
ext/standard/var_unserializer.re
ext/zip/php_zip.c
ext/zlib/zlib.c
main/php_variables.c

index 817d35a759a9668c3c7378f58ce20c98cdd364ce..492a259778186721e9052535af83c713da711a5a 100644 (file)
@@ -1878,13 +1878,13 @@ ZEND_API int zend_startup_module_ex(zend_module_entry *module) /* {{{ */
                                zend_str_tolower_copy(ZSTR_VAL(lcname), dep->name, name_len);
 
                                if ((req_mod = zend_hash_find_ptr(&module_registry, lcname)) == NULL || !req_mod->module_started) {
-                                       zend_string_free(lcname);
+                                       zend_string_efree(lcname);
                                        /* TODO: Check version relationship */
                                        zend_error(E_CORE_WARNING, "Cannot load module '%s' because required module '%s' is not loaded", module->name, dep->name);
                                        module->module_started = 0;
                                        return FAILURE;
                                }
-                               zend_string_free(lcname);
+                               zend_string_efree(lcname);
                        }
                        ++dep;
                }
@@ -2066,12 +2066,12 @@ ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module) /
                                zend_str_tolower_copy(ZSTR_VAL(lcname), dep->name, name_len);
 
                                if (zend_hash_exists(&module_registry, lcname) || zend_get_extension(dep->name)) {
-                                       zend_string_free(lcname);
+                                       zend_string_efree(lcname);
                                        /* TODO: Check version relationship */
                                        zend_error(E_CORE_WARNING, "Cannot load module '%s' because conflicting module '%s' is already loaded", module->name, dep->name);
                                        return NULL;
                                }
-                               zend_string_free(lcname);
+                               zend_string_efree(lcname);
                        }
                        ++dep;
                }
@@ -2411,7 +2411,7 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
                        if (zend_hash_exists(target_function_table, lowercase_name)) {
                                zend_error(error_type, "Function registration failed - duplicate name - %s%s%s", scope ? ZSTR_VAL(scope->name) : "", scope ? "::" : "", ptr->fname);
                        }
-                       zend_string_free(lowercase_name);
+                       zend_string_efree(lowercase_name);
                        ptr++;
                }
                zend_unregister_functions(functions, count, target_function_table);
@@ -2536,7 +2536,7 @@ ZEND_API void zend_unregister_functions(const zend_function_entry *functions, in
                lowercase_name = zend_string_alloc(fname_len, 0);
                zend_str_tolower_copy(ZSTR_VAL(lowercase_name), ptr->fname, fname_len);
                zend_hash_del(target_function_table, lowercase_name);
-               zend_string_free(lowercase_name);
+               zend_string_efree(lowercase_name);
                ptr++;
                i++;
        }
@@ -3698,7 +3698,7 @@ ZEND_API const char *zend_get_module_version(const char *module_name) /* {{{ */
        lname = zend_string_alloc(name_len, 0);
        zend_str_tolower_copy(ZSTR_VAL(lname), module_name, name_len);
        module = zend_hash_find_ptr(&module_registry, lname);
-       zend_string_free(lname);
+       zend_string_efree(lname);
        return module ? module->version : NULL;
 }
 /* }}} */
@@ -4096,7 +4096,7 @@ ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *na
        EG(fake_scope) = scope;
        property = zend_std_get_static_property(scope, key, 0);
        EG(fake_scope) = old_scope;
-       zend_string_free(key);
+       zend_string_efree(key);
        if (!property) {
                return FAILURE;
        } else {
@@ -4222,7 +4222,7 @@ ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *na
        EG(fake_scope) = scope;
        property = zend_std_get_static_property(scope, key, silent);
        EG(fake_scope) = old_scope;
-       zend_string_free(key);
+       zend_string_efree(key);
 
        return property;
 }
index 448856dd92be60076cdad6e4d77478f1822e4c79..08c530d363d8feacabdf762cdc1b47b5dbbf21ba 100644 (file)
@@ -6588,7 +6588,7 @@ void zend_compile_use(zend_ast *ast) /* {{{ */
                                zend_check_already_in_use(type, old_name, new_name, ns_name);
                        }
 
-                       zend_string_free(ns_name);
+                       zend_string_efree(ns_name);
                } else {
                        if (zend_have_seen_symbol(lookup_name, type)) {
                                zend_check_already_in_use(type, old_name, new_name, lookup_name);
index a2e25c89df6c54e6cca8c98f80334ca1389a2055..b07901c47057b59696403f4926d644da08ff717d 100644 (file)
@@ -226,7 +226,7 @@ static zend_constant *zend_get_special_constant(const char *name, size_t name_le
                haltname = zend_mangle_property_name(haltoff,
                        sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0);
                c = zend_hash_find_ptr(EG(zend_constants), haltname);
-               zend_string_free(haltname);
+               zend_string_efree(haltname);
                return c;
        } else {
                return NULL;
@@ -379,7 +379,7 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
                }
 failure:
                zend_string_release(class_name);
-               zend_string_free(constant_name);
+               zend_string_efree(constant_name);
                return ret_constant;
        }
 
index 46a674ba903b8cfe0ba027d91dc1f289700b0ead..8af706a1d03718deb4cf1b6aa41c092d7efe0a75 100644 (file)
@@ -619,8 +619,8 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
                        error_verb = "should";
                }
                zend_error(error_level, "Declaration of %s %s be compatible with %s", ZSTR_VAL(child_prototype), error_verb, ZSTR_VAL(method_prototype));
-               zend_string_free(child_prototype);
-               zend_string_free(method_prototype);
+               zend_string_efree(child_prototype);
+               zend_string_efree(method_prototype);
        }
 }
 /* }}} */
index 42e209ab91bf9d2990acd21899159be1dc4b8ddd..f9a316ac230dd1b1681abe09ac3ae3a91e5272fd 100644 (file)
@@ -2034,11 +2034,11 @@ heredoc_scan_done:
                }
 
                if (UNEXPECTED(zend_scan_escape_string(zendlval, ZSTR_VAL(copy), ZSTR_LEN(copy), 0) != SUCCESS)) {
-                       zend_string_free(copy);
+                       zend_string_efree(copy);
                        RETURN_TOKEN(T_ERROR);
                }
 
-               zend_string_free(copy);
+               zend_string_efree(copy);
        } else {
                HANDLE_NEWLINES(yytext, yyleng - newline);
        }
index 15afc4388733a8e0e152be4834906b7f26df75de..fb4b7386e5b74f9b7ee576260a8baafd5f29bbe8 100644 (file)
@@ -2620,11 +2620,11 @@ heredoc_scan_done:
                }
 
                if (UNEXPECTED(zend_scan_escape_string(zendlval, ZSTR_VAL(copy), ZSTR_LEN(copy), 0) != SUCCESS)) {
-                       zend_string_free(copy);
+                       zend_string_efree(copy);
                        RETURN_TOKEN(T_ERROR);
                }
 
-               zend_string_free(copy);
+               zend_string_efree(copy);
        } else {
                HANDLE_NEWLINES(yytext, yyleng - newline);
        }
index fe2a7475c407b8ed03049e3fbb5cae4f4418a7ba..d517b740207a86a7586632af62623b02387bd055 100644 (file)
@@ -264,6 +264,14 @@ static zend_always_inline void zend_string_free(zend_string *s)
        }
 }
 
+static zend_always_inline void zend_string_efree(zend_string *s)
+{
+       ZEND_ASSERT(!ZSTR_IS_INTERNED(s));
+       ZEND_ASSERT(GC_REFCOUNT(s) <= 1);
+       ZEND_ASSERT(!(GC_FLAGS(s) & IS_STR_PERSISTENT));
+       efree(s);
+}
+
 static zend_always_inline void zend_string_release(zend_string *s)
 {
        if (!ZSTR_IS_INTERNED(s)) {
index 502c9a7062563de5c0d8a662918b3f7450d25154..2d6ffc28ea8be1c2745389abf7a07e1123e52690 100644 (file)
@@ -546,7 +546,7 @@ static PHP_FUNCTION(bzcompress)
 
        error = BZ2_bzBuffToBuffCompress(ZSTR_VAL(dest), &dest_len, source, source_len, block_size, 0, work_factor);
        if (error != BZ_OK) {
-               zend_string_free(dest);
+               zend_string_efree(dest);
                RETURN_LONG(error);
        } else {
                /* Copy the buffer, we have perhaps allocate a lot more than we need,
@@ -612,7 +612,7 @@ static PHP_FUNCTION(bzdecompress)
 #if !ZEND_ENABLE_ZVAL_LONG64
                if (UNEXPECTED(size > SIZE_MAX)) {
                        php_error_docref(NULL, E_WARNING, "Decompressed size too big, max is %zd", SIZE_MAX);
-                       zend_string_free(dest);
+                       zend_string_efree(dest);
                        RETVAL_LONG(BZ_MEM_ERROR);
                } else
 #endif
@@ -623,7 +623,7 @@ static PHP_FUNCTION(bzdecompress)
                        RETVAL_STR(dest);
                }
        } else { /* real error */
-               zend_string_free(dest);
+               zend_string_efree(dest);
                RETVAL_LONG(error);
        }
 
index ed92dd5f0db7aca20cbdfba01d208f376bd8fd9a..be1df2d81cedd0bed9dc886944605cc16f014b41 100644 (file)
@@ -1738,7 +1738,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
                buf = zend_string_truncate(buf, real_len, 0);
                RETURN_NEW_STR(buf);
        }
-       zend_string_free(buf);
+       zend_string_efree(buf);
        RETURN_FALSE;
 }
 /* }}} */
index 4ebce2c156d433939c15d023edb4f58e8b35cdb2..34641d882c55c9dd8066bd0ef7f65a632c00878a 100644 (file)
@@ -438,7 +438,7 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c
                if (out) {
                        output_context->out.data = estrndup(ZSTR_VAL(out), ZSTR_LEN(out));
                        output_context->out.used = ZSTR_LEN(out);
-                       zend_string_free(out);
+                       zend_string_efree(out);
                } else {
                        output_context->out.data = NULL;
                        output_context->out.used = 0;
@@ -585,7 +585,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
        result = iconv(cd, (const char **) &in_p, &in_size, (char **) &out_p, &out_left);
 
        if (result == (size_t)(-1)) {
-               zend_string_free(out_buffer);
+               zend_string_efree(out_buffer);
                return PHP_ICONV_ERR_UNKNOWN;
        }
 
@@ -601,7 +601,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
        result = iconv(cd, NULL, NULL, &out_p, &out_left);
 
        if (result == (size_t)(-1)) {
-               zend_string_free(out_buffer);
+               zend_string_efree(out_buffer);
                return PHP_ICONV_ERR_UNKNOWN;
        }
 
@@ -713,7 +713,7 @@ PHP_ICONV_API php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len,
 
                        default:
                                /* other error */
-                               zend_string_free(out_buf);
+                               zend_string_efree(out_buf);
                                return PHP_ICONV_ERR_UNKNOWN;
                }
        }
@@ -987,7 +987,7 @@ static php_iconv_err_t _php_iconv_strpos(size_t *pretval,
 
        if (err != PHP_ICONV_ERR_SUCCESS) {
                if (ndl_buf != NULL) {
-                       zend_string_free(ndl_buf);
+                       zend_string_efree(ndl_buf);
                }
                return err;
        }
@@ -996,7 +996,7 @@ static php_iconv_err_t _php_iconv_strpos(size_t *pretval,
 
        if (cd == (iconv_t)(-1)) {
                if (ndl_buf != NULL) {
-                       zend_string_free(ndl_buf);
+                       zend_string_efree(ndl_buf);
                }
 #if ICONV_SUPPORTS_ERRNO
                if (errno == EINVAL) {
@@ -1131,7 +1131,7 @@ static php_iconv_err_t _php_iconv_strpos(size_t *pretval,
        }
 
        if (ndl_buf) {
-               zend_string_free(ndl_buf);
+               zend_string_efree(ndl_buf);
        }
 
        iconv_close(cd);
@@ -2463,10 +2463,10 @@ PHP_NAMED_FUNCTION(php_if_iconv)
        err = php_iconv_string(ZSTR_VAL(in_buffer), (size_t)ZSTR_LEN(in_buffer), &out_buffer, out_charset, in_charset);
        _php_iconv_show_error(err, out_charset, in_charset);
        if (err == PHP_ICONV_ERR_SUCCESS && out_buffer != NULL) {
-               RETVAL_STR(out_buffer);
+               RETVAL_NEW_STR(out_buffer);
        } else {
                if (out_buffer != NULL) {
-                       zend_string_free(out_buffer);
+                       zend_string_efree(out_buffer);
                }
                RETURN_FALSE;
        }
index f54006fe69d71ff0b30c3b9d55cc078de0c51cd7..e26173b10aa409e722ca9469081c537c4df87380 100644 (file)
@@ -705,7 +705,7 @@ static zend_string* php_converter_do_convert(UConverter *dest_cnv,
        efree(temp);
        if (U_FAILURE(error)) {
                THROW_UFAILURE(objval, "ucnv_fromUChars", error);
-               zend_string_free(ret);
+               zend_string_efree(ret);
                return NULL;
        }
 
index a7f40ba66ea498efd00300879263a8ce04dbb15b..02e341fa3879ce6ac5a2be530300b755ed591cdf 100644 (file)
@@ -146,7 +146,7 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
 
        uts46 = uidna_openUTS46(option, &status);
        if (php_intl_idn_check_status(status, "failed to open UIDNA instance") == FAILURE) {
-               zend_string_free(buffer);
+               zend_string_efree(buffer);
                RETURN_FALSE;
        }
 
@@ -159,7 +159,7 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
        }
        if (len >= 255 || php_intl_idn_check_status(status, "failed to convert name") == FAILURE) {
                uidna_close(uts46);
-               zend_string_free(buffer);
+               zend_string_efree(buffer);
                RETURN_FALSE;
        }
 
@@ -189,7 +189,7 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
        }
 
        if (!buffer_used) {
-               zend_string_free(buffer);
+               zend_string_efree(buffer);
        }
 
        uidna_close(uts46);
index 2ae43fbb96a94842f4a0d5f1886689101b95c5c3..eadcf2c9f11552b94e0b723656f10316109e1653 100644 (file)
@@ -141,7 +141,7 @@ zend_string* intl_convert_utf16_to_utf8(
        u_strToUTF8( ZSTR_VAL(dst), dst_len, NULL, src, src_len, status );
        if( U_FAILURE( *status ) )
        {
-               zend_string_free(dst);
+               zend_string_efree(dst);
                return NULL;
        }
 
index d12df97a38067dfb7582f441ee2ee500061db73a..f300fa88ff606a23a8134f98a1c9ace8497a901c 100644 (file)
@@ -742,7 +742,7 @@ PHP_FUNCTION( locale_get_keywords )
                        if (U_FAILURE(status)) {
                                intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "locale_get_keywords: Error encountered while getting the keyword  value for the  keyword", 0 );
                                if( kw_value_str){
-                                       zend_string_free( kw_value_str );
+                                       zend_string_efree( kw_value_str );
                                }
                                zval_dtor(return_value);
                        RETURN_FALSE;
index 2cec0a4b8a0613a3250ab6a47aa7ab92382e5296..c3fe66f823c182c9a30e3cd862f6a90ef7e33332 100644 (file)
@@ -261,7 +261,7 @@ IC_METHOD(charName) {
        error = U_ZERO_ERROR;
        buffer_len = u_charName(cp, (UCharNameChoice)nameChoice, ZSTR_VAL(buffer), ZSTR_LEN(buffer) + 1, &error);
        if (U_FAILURE(error)) {
-               zend_string_free(buffer);
+               zend_string_efree(buffer);
                INTL_CHECK_STATUS_OR_NULL(error, "Failure getting character name");
        }
        RETURN_NEW_STR(buffer);
index 86756654449a81042e2ee2bb476ddd8b5cdee183..fefb6d91b259de34bc61e19509a0868c13fd84a5 100644 (file)
@@ -2193,15 +2193,15 @@ PHP_FUNCTION(odbc_result)
 
                        if (rc == SQL_ERROR) {
                                odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
-                               zend_string_free(field_str);
+                               zend_string_efree(field_str);
                                RETURN_FALSE;
                        }
 
                        if (result->values[field_ind].vallen == SQL_NULL_DATA) {
-                               zend_string_free(field_str);
+                               zend_string_efree(field_str);
                                RETURN_NULL();
                        } else if (rc == SQL_NO_DATA_FOUND) {
-                               zend_string_free(field_str);
+                               zend_string_efree(field_str);
                                RETURN_FALSE;
                        }
                        /* Reduce fieldlen by 1 if we have char data. One day we might
index 81a1bdbb3c92dda355d7f964e859d5b61f13f4f7..f0873ce854b375443cf432b66b0e2a93ccf81c97 100644 (file)
@@ -3531,7 +3531,7 @@ PHP_FUNCTION(pg_lo_read)
 
        buf = zend_string_alloc(buf_len, 0);
        if ((nbytes = lo_read((PGconn *)pgsql->conn, pgsql->lofd, ZSTR_VAL(buf), ZSTR_LEN(buf)))<0) {
-               zend_string_free(buf);
+               zend_string_efree(buf);
                RETURN_FALSE;
        }
 
index 391183addfe7cf3ab44c00320ebad1ab3209cb16..87ffeba666ccde783749927c43ba542dce19430a 100644 (file)
@@ -1130,7 +1130,7 @@ static void reflection_extension_factory(zval *object, const char *name_str)
        lcname = zend_string_alloc(name_len, 0);
        zend_str_tolower_copy(ZSTR_VAL(lcname), name_str, name_len);
        module = zend_hash_find_ptr(&module_registry, lcname);
-       zend_string_free(lcname);
+       zend_string_efree(lcname);
        if (!module) {
                return;
        }
index e8834479dc8481762554a9504d5da5d2d9cec240..104eaf339efa87a0d198596b97acedc1ec84f6a9 100644 (file)
@@ -1232,10 +1232,10 @@ PHP_FUNCTION(socket_read)
                        PHP_SOCKET_ERROR(php_sock, "unable to read from socket", errno);
                }
 
-               zend_string_free(tmpbuf);
+               zend_string_efree(tmpbuf);
                RETURN_FALSE;
        } else if (!retval) {
-               zend_string_free(tmpbuf);
+               zend_string_efree(tmpbuf);
                RETURN_EMPTY_STRING();
        }
 
@@ -1670,7 +1670,7 @@ PHP_FUNCTION(socket_recv)
        recv_buf = zend_string_alloc(len, 0);
 
        if ((retval = recv(php_sock->bsd_socket, ZSTR_VAL(recv_buf), len, flags)) < 1) {
-               zend_string_free(recv_buf);
+               zend_string_efree(recv_buf);
 
                zval_ptr_dtor(buf);
                ZVAL_NULL(buf);
@@ -1762,7 +1762,7 @@ PHP_FUNCTION(socket_recvfrom)
 
                        if (retval < 0) {
                                PHP_SOCKET_ERROR(php_sock, "unable to recvfrom", errno);
-                               zend_string_free(recv_buf);
+                               zend_string_efree(recv_buf);
                                RETURN_FALSE;
                        }
                        ZSTR_LEN(recv_buf) = retval;
@@ -1781,7 +1781,7 @@ PHP_FUNCTION(socket_recvfrom)
                        sin.sin_family = AF_INET;
 
                        if (arg6 == NULL) {
-                               zend_string_free(recv_buf);
+                               zend_string_efree(recv_buf);
                                WRONG_PARAM_COUNT;
                        }
 
@@ -1789,7 +1789,7 @@ PHP_FUNCTION(socket_recvfrom)
 
                        if (retval < 0) {
                                PHP_SOCKET_ERROR(php_sock, "unable to recvfrom", errno);
-                               zend_string_free(recv_buf);
+                               zend_string_efree(recv_buf);
                                RETURN_FALSE;
                        }
                        ZSTR_LEN(recv_buf) = retval;
@@ -1812,7 +1812,7 @@ PHP_FUNCTION(socket_recvfrom)
                        sin6.sin6_family = AF_INET6;
 
                        if (arg6 == NULL) {
-                               zend_string_free(recv_buf);
+                               zend_string_efree(recv_buf);
                                WRONG_PARAM_COUNT;
                        }
 
@@ -1820,7 +1820,7 @@ PHP_FUNCTION(socket_recvfrom)
 
                        if (retval < 0) {
                                PHP_SOCKET_ERROR(php_sock, "unable to recvfrom", errno);
-                               zend_string_free(recv_buf);
+                               zend_string_efree(recv_buf);
                                RETURN_FALSE;
                        }
                        ZSTR_LEN(recv_buf) = retval;
index d7af877b1fb12423687454056580728212e95d2d..5791bc5114c7b7f5cd2c8d8e6e56a5f5e3a8515a 100644 (file)
@@ -768,13 +768,13 @@ PHP_FUNCTION(sodium_crypto_shorthash)
        hash = zend_string_alloc(crypto_shorthash_BYTES, 0);
        if (crypto_shorthash((unsigned char *) ZSTR_VAL(hash), msg,
                                                 (unsigned long long) msg_len, key) != 0) {
-               zend_string_free(hash);
+               zend_string_efree(hash);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(hash)[crypto_shorthash_BYTES] = 0;
 
-       RETURN_STR(hash);
+       RETURN_NEW_STR(hash);
 }
 
 PHP_FUNCTION(sodium_crypto_secretbox)
@@ -814,13 +814,13 @@ PHP_FUNCTION(sodium_crypto_secretbox)
        if (crypto_secretbox_easy((unsigned char *) ZSTR_VAL(ciphertext),
                                                          msg, (unsigned long long) msg_len,
                                                          nonce, key) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(ciphertext)[msg_len + crypto_secretbox_MACBYTES] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 PHP_FUNCTION(sodium_crypto_secretbox_open)
@@ -860,11 +860,11 @@ PHP_FUNCTION(sodium_crypto_secretbox_open)
        if (crypto_secretbox_open_easy((unsigned char *) ZSTR_VAL(msg), ciphertext,
                                                                   (unsigned long long) ciphertext_len,
                                                                   nonce, key) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        } else {
                ZSTR_VAL(msg)[ciphertext_len - crypto_secretbox_MACBYTES] = 0;
-               RETURN_STR(msg);
+               RETURN_NEW_STR(msg);
        }
 }
 
@@ -899,13 +899,13 @@ PHP_FUNCTION(sodium_crypto_generichash)
        if (crypto_generichash((unsigned char *) ZSTR_VAL(hash), (size_t) hash_len,
                                                   msg, (unsigned long long) msg_len,
                                                   key, (size_t) key_len) != 0) {
-               zend_string_free(hash);
+               zend_string_efree(hash);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(hash)[hash_len] = 0;
 
-       RETURN_STR(hash);
+       RETURN_NEW_STR(hash);
 }
 
 PHP_FUNCTION(sodium_crypto_generichash_init)
@@ -1023,7 +1023,7 @@ PHP_FUNCTION(sodium_crypto_generichash_final)
                                                                 (unsigned char *) ZSTR_VAL(hash),
                                                                 (size_t) hash_len) != 0) {
                sodium_memzero(&state_tmp, sizeof state_tmp);
-               zend_string_free(hash);
+               zend_string_efree(hash);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
@@ -1032,7 +1032,7 @@ PHP_FUNCTION(sodium_crypto_generichash_final)
        convert_to_null(state_zv);
        ZSTR_VAL(hash)[hash_len] = 0;
 
-       RETURN_STR(hash);
+       RETURN_NEW_STR(hash);
 }
 
 PHP_FUNCTION(sodium_crypto_box_keypair)
@@ -1048,13 +1048,13 @@ PHP_FUNCTION(sodium_crypto_box_keypair)
        if (crypto_box_keypair((unsigned char *) ZSTR_VAL(keypair) +
                                                   crypto_box_SECRETKEYBYTES,
                                                   (unsigned char *) ZSTR_VAL(keypair)) != 0) {
-               zend_string_free(keypair);
+               zend_string_efree(keypair);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(keypair)[keypair_len] = 0;
 
-       RETURN_STR(keypair);
+       RETURN_NEW_STR(keypair);
 }
 
 PHP_FUNCTION(sodium_crypto_box_seed_keypair)
@@ -1081,13 +1081,13 @@ PHP_FUNCTION(sodium_crypto_box_seed_keypair)
                                                                 crypto_box_SECRETKEYBYTES,
                                                                 (unsigned char *) ZSTR_VAL(keypair),
                                                                 seed) != 0) {
-               zend_string_free(keypair);
+               zend_string_efree(keypair);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(keypair)[keypair_len] = 0;
 
-       RETURN_STR(keypair);
+       RETURN_NEW_STR(keypair);
 }
 
 PHP_FUNCTION(sodium_crypto_box_keypair_from_secretkey_and_publickey)
@@ -1247,13 +1247,13 @@ PHP_FUNCTION(sodium_crypto_box)
        if (crypto_box_easy((unsigned char *) ZSTR_VAL(ciphertext), msg,
                                                (unsigned long long) msg_len,
                                                nonce, publickey, secretkey) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(ciphertext)[msg_len + crypto_box_MACBYTES] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 PHP_FUNCTION(sodium_crypto_box_open)
@@ -1296,11 +1296,11 @@ PHP_FUNCTION(sodium_crypto_box_open)
        if (crypto_box_open_easy((unsigned char *) ZSTR_VAL(msg), ciphertext,
                                                         (unsigned long long) ciphertext_len,
                                                         nonce, publickey, secretkey) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        } else {
                ZSTR_VAL(msg)[ciphertext_len - crypto_box_MACBYTES] = 0;
-               RETURN_STR(msg);
+               RETURN_NEW_STR(msg);
        }
 }
 
@@ -1331,13 +1331,13 @@ PHP_FUNCTION(sodium_crypto_box_seal)
        ciphertext = zend_string_alloc((size_t) msg_len + crypto_box_SEALBYTES, 0);
        if (crypto_box_seal((unsigned char *) ZSTR_VAL(ciphertext), msg,
                                                (unsigned long long) msg_len, publickey) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(ciphertext)[msg_len + crypto_box_SEALBYTES] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 PHP_FUNCTION(sodium_crypto_box_seal_open)
@@ -1371,11 +1371,11 @@ PHP_FUNCTION(sodium_crypto_box_seal_open)
        if (crypto_box_seal_open((unsigned char *) ZSTR_VAL(msg), ciphertext,
                                                         (unsigned long long) ciphertext_len,
                                                         publickey, secretkey) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        } else {
                ZSTR_VAL(msg)[ciphertext_len - crypto_box_SEALBYTES] = 0;
-               RETURN_STR(msg);
+               RETURN_NEW_STR(msg);
        }
 }
 
@@ -1392,13 +1392,13 @@ PHP_FUNCTION(sodium_crypto_sign_keypair)
        if (crypto_sign_keypair((unsigned char *) ZSTR_VAL(keypair) +
                                                        crypto_sign_SECRETKEYBYTES,
                                                        (unsigned char *) ZSTR_VAL(keypair)) != 0) {
-               zend_string_free(keypair);
+               zend_string_efree(keypair);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(keypair)[keypair_len] = 0;
 
-       RETURN_STR(keypair);
+       RETURN_NEW_STR(keypair);
 }
 
 PHP_FUNCTION(sodium_crypto_sign_seed_keypair)
@@ -1425,13 +1425,13 @@ PHP_FUNCTION(sodium_crypto_sign_seed_keypair)
                                                                 crypto_sign_SECRETKEYBYTES,
                                                                 (unsigned char *) ZSTR_VAL(keypair),
                                                                 seed) != 0) {
-               zend_string_free(keypair);
+               zend_string_efree(keypair);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(keypair)[keypair_len] = 0;
 
-       RETURN_STR(keypair);
+       RETURN_NEW_STR(keypair);
 }
 
 PHP_FUNCTION(sodium_crypto_sign_keypair_from_secretkey_and_publickey)
@@ -1583,19 +1583,19 @@ PHP_FUNCTION(sodium_crypto_sign)
        if (crypto_sign((unsigned char *) ZSTR_VAL(msg_signed),
                                        &msg_signed_real_len, msg,
                                        (unsigned long long) msg_len, secretkey) != 0) {
-               zend_string_free(msg_signed);
+               zend_string_efree(msg_signed);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        if (msg_signed_real_len >= SIZE_MAX || msg_signed_real_len > msg_signed_len) {
-               zend_string_free(msg_signed);
+               zend_string_efree(msg_signed);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(msg_signed, (size_t) msg_signed_real_len);
        ZSTR_VAL(msg_signed)[msg_signed_real_len] = 0;
 
-       RETURN_STR(msg_signed);
+       RETURN_NEW_STR(msg_signed);
 }
 
 PHP_FUNCTION(sodium_crypto_sign_open)
@@ -1629,18 +1629,18 @@ PHP_FUNCTION(sodium_crypto_sign_open)
        if (crypto_sign_open((unsigned char *) ZSTR_VAL(msg), &msg_real_len,
                                                 msg_signed, (unsigned long long) msg_signed_len,
                                                 publickey) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        }
        if (msg_real_len >= SIZE_MAX || msg_real_len > msg_signed_len) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len);
        ZSTR_VAL(msg)[msg_real_len] = 0;
 
-       RETURN_STR(msg);
+       RETURN_NEW_STR(msg);
 }
 
 PHP_FUNCTION(sodium_crypto_sign_detached)
@@ -1669,18 +1669,18 @@ PHP_FUNCTION(sodium_crypto_sign_detached)
        if (crypto_sign_detached((unsigned char *) ZSTR_VAL(signature),
                                                         &signature_real_len, msg,
                                                         (unsigned long long) msg_len, secretkey) != 0) {
-               zend_string_free(signature);
+               zend_string_efree(signature);
                zend_throw_exception(sodium_exception_ce, "signature creation failed", 0);
                return;
        }
        if (signature_real_len <= 0U || signature_real_len > crypto_sign_BYTES) {
-               zend_string_free(signature);
+               zend_string_efree(signature);
                zend_throw_exception(sodium_exception_ce, "signature has a bogus size", 0);
                return;
        }
        ZEND_ASSERT(ZSTR_VAL(signature)[signature_real_len] == 0);
 
-       RETURN_STR(signature);
+       RETURN_NEW_STR(signature);
 }
 
 PHP_FUNCTION(sodium_crypto_sign_verify_detached)
@@ -1750,13 +1750,13 @@ PHP_FUNCTION(sodium_crypto_stream)
        ciphertext = zend_string_alloc((size_t) ciphertext_len, 0);
        if (crypto_stream((unsigned char *) ZSTR_VAL(ciphertext),
                                          (unsigned long long) ciphertext_len, nonce, key) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(ciphertext)[ciphertext_len] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 PHP_FUNCTION(sodium_crypto_stream_xor)
@@ -1789,13 +1789,13 @@ PHP_FUNCTION(sodium_crypto_stream_xor)
        ciphertext = zend_string_alloc((size_t) ciphertext_len, 0);
        if (crypto_stream_xor((unsigned char *) ZSTR_VAL(ciphertext), msg,
                                                  (unsigned long long) msg_len, nonce, key) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(ciphertext)[ciphertext_len] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 #ifdef crypto_pwhash_SALTBYTES
@@ -1878,13 +1878,13 @@ PHP_FUNCTION(sodium_crypto_pwhash)
                          (unsigned long long) opslimit, (size_t) memlimit, (int) alg);
        }
        if (ret != 0) {
-               zend_string_free(hash);
+               zend_string_efree(hash);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(hash)[hash_len] = 0;
 
-       RETURN_STR(hash);
+       RETURN_NEW_STR(hash);
 }
 
 PHP_FUNCTION(sodium_crypto_pwhash_str)
@@ -1929,7 +1929,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_str)
        if (crypto_pwhash_str
                (ZSTR_VAL(hash_str), passwd, (unsigned long long) passwd_len,
                 (unsigned long long) opslimit, (size_t) memlimit) != 0) {
-               zend_string_free(hash_str);
+               zend_string_efree(hash_str);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
@@ -1938,7 +1938,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_str)
        len = strlen(ZSTR_VAL(hash_str));
        PHP_SODIUM_ZSTR_TRUNCATE(hash_str, len);
 
-       RETURN_STR(hash_str);
+       RETURN_NEW_STR(hash_str);
 }
 
 #if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
@@ -2044,13 +2044,13 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256)
                ((unsigned char *) ZSTR_VAL(hash), (unsigned long long) hash_len,
                 passwd, (unsigned long long) passwd_len, salt,
                 (unsigned long long) opslimit, (size_t) memlimit) != 0) {
-               zend_string_free(hash);
+               zend_string_efree(hash);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(hash)[hash_len] = 0;
 
-       RETURN_STR(hash);
+       RETURN_NEW_STR(hash);
 }
 
 PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str)
@@ -2091,13 +2091,13 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str)
        if (crypto_pwhash_scryptsalsa208sha256_str
                (ZSTR_VAL(hash_str), passwd, (unsigned long long) passwd_len,
                 (unsigned long long) opslimit, (size_t) memlimit) != 0) {
-               zend_string_free(hash_str);
+               zend_string_efree(hash_str);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(hash_str)[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1] = 0;
 
-       RETURN_STR(hash_str);
+       RETURN_NEW_STR(hash_str);
 }
 
 PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str_verify)
@@ -2191,20 +2191,20 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt)
                ((unsigned char *) ZSTR_VAL(ciphertext), &ciphertext_real_len, msg,
                 (unsigned long long) msg_len,
                 ad, (unsigned long long) ad_len, NULL, npub, secretkey) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
                ciphertext_real_len > ciphertext_len) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(ciphertext, (size_t) ciphertext_real_len);
        ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt)
@@ -2260,18 +2260,18 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt)
                ((unsigned char *) ZSTR_VAL(msg), &msg_real_len, NULL,
                 ciphertext, (unsigned long long) ciphertext_len,
                 ad, (unsigned long long) ad_len, npub, secretkey) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        }
        if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len);
        ZSTR_VAL(msg)[msg_real_len] = 0;
 
-       RETURN_STR(msg);
+       RETURN_NEW_STR(msg);
 }
 #endif
 
@@ -2321,20 +2321,20 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt)
                ((unsigned char *) ZSTR_VAL(ciphertext), &ciphertext_real_len, msg,
                 (unsigned long long) msg_len,
                 ad, (unsigned long long) ad_len, NULL, npub, secretkey) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
                ciphertext_real_len > ciphertext_len) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(ciphertext, (size_t) ciphertext_real_len);
        ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt)
@@ -2386,18 +2386,18 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt)
                ((unsigned char *) ZSTR_VAL(msg), &msg_real_len, NULL,
                 ciphertext, (unsigned long long) ciphertext_len,
                 ad, (unsigned long long) ad_len, npub, secretkey) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        }
        if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len);
        ZSTR_VAL(msg)[msg_real_len] = 0;
 
-       RETURN_STR(msg);
+       RETURN_NEW_STR(msg);
 }
 
 PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt)
@@ -2450,20 +2450,20 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt)
                ((unsigned char *) ZSTR_VAL(ciphertext), &ciphertext_real_len, msg,
                 (unsigned long long) msg_len,
                 ad, (unsigned long long) ad_len, NULL, npub, secretkey) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
                ciphertext_real_len > ciphertext_len) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(ciphertext, (size_t) ciphertext_real_len);
        ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt)
@@ -2520,18 +2520,18 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt)
                ((unsigned char *) ZSTR_VAL(msg), &msg_real_len, NULL,
                 ciphertext, (unsigned long long) ciphertext_len,
                 ad, (unsigned long long) ad_len, npub, secretkey) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        }
        if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len);
        ZSTR_VAL(msg)[msg_real_len] = 0;
 
-       RETURN_STR(msg);
+       RETURN_NEW_STR(msg);
 }
 
 #ifdef crypto_aead_xchacha20poly1305_IETF_NPUBBYTES
@@ -2581,20 +2581,20 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt)
                ((unsigned char *) ZSTR_VAL(ciphertext), &ciphertext_real_len, msg,
                 (unsigned long long) msg_len,
                 ad, (unsigned long long) ad_len, NULL, npub, secretkey) != 0) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX ||
                ciphertext_real_len > ciphertext_len) {
-               zend_string_free(ciphertext);
+               zend_string_efree(ciphertext);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(ciphertext, (size_t) ciphertext_real_len);
        ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0;
 
-       RETURN_STR(ciphertext);
+       RETURN_NEW_STR(ciphertext);
 }
 
 PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt)
@@ -2651,18 +2651,18 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt)
                ((unsigned char *) ZSTR_VAL(msg), &msg_real_len, NULL,
                 ciphertext, (unsigned long long) ciphertext_len,
                 ad, (unsigned long long) ad_len, npub, secretkey) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        }
        if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len);
        ZSTR_VAL(msg)[msg_real_len] = 0;
 
-       RETURN_STR(msg);
+       RETURN_NEW_STR(msg);
 }
 #endif
 
@@ -2712,19 +2712,19 @@ PHP_FUNCTION(sodium_hex2bin)
        if (sodium_hex2bin((unsigned char *) ZSTR_VAL(bin), bin_len, hex, hex_len,
                                           ignore, &bin_real_len, &end) != 0 ||
                end != hex + hex_len) {
-               zend_string_free(bin);
+               zend_string_efree(bin);
                zend_throw_exception(sodium_exception_ce, "invalid hex string", 0);
                return;
        }
        if (bin_real_len >= SIZE_MAX || bin_real_len > bin_len) {
-               zend_string_free(bin);
+               zend_string_efree(bin);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(bin, (size_t) bin_real_len);
        ZSTR_VAL(bin)[bin_real_len] = 0;
 
-       RETURN_STR(bin);
+       RETURN_NEW_STR(bin);
 }
 
 #ifdef sodium_base64_VARIANT_ORIGINAL
@@ -2786,19 +2786,19 @@ PHP_FUNCTION(sodium_base642bin)
                                                  b64, b64_len,
                                                  ignore, &bin_real_len, &end, (int) variant) != 0 ||
                end != b64 + b64_len) {
-               zend_string_free(bin);
+               zend_string_efree(bin);
                zend_throw_exception(sodium_exception_ce, "invalid base64 string", 0);
                return;
        }
        if (bin_real_len >= SIZE_MAX || bin_real_len > bin_len) {
-               zend_string_free(bin);
+               zend_string_efree(bin);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(bin, (size_t) bin_real_len);
        ZSTR_VAL(bin)[bin_real_len] = 0;
 
-       RETURN_STR(bin);
+       RETURN_NEW_STR(bin);
 }
 #endif
 
@@ -2824,13 +2824,13 @@ PHP_FUNCTION(sodium_crypto_scalarmult)
        }
        q = zend_string_alloc(crypto_scalarmult_BYTES, 0);
        if (crypto_scalarmult((unsigned char *) ZSTR_VAL(q), n, p) != 0) {
-               zend_string_free(q);
+               zend_string_efree(q);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        ZSTR_VAL(q)[crypto_scalarmult_BYTES] = 0;
 
-       RETURN_STR(q);
+       RETURN_NEW_STR(q);
 }
 
 PHP_FUNCTION(sodium_crypto_kx_seed_keypair)
@@ -3585,19 +3585,19 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push)
                ((void *) state, (unsigned char *) ZSTR_VAL(c), &c_real_len,
                 msg, (unsigned long long) msg_len, ad, (unsigned long long) ad_len,
                 (unsigned char) tag) != 0) {
-               zend_string_free(c);
+               zend_string_efree(c);
                zend_throw_exception(sodium_exception_ce, "internal error", 0);
                return;
        }
        if (c_real_len <= 0U || c_real_len >= SIZE_MAX || c_real_len > c_len) {
-               zend_string_free(c);
+               zend_string_efree(c);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
        PHP_SODIUM_ZSTR_TRUNCATE(c, (size_t) c_real_len);
        ZSTR_VAL(c)[c_real_len] = 0;
 
-       RETURN_STR(c);
+       RETURN_NEW_STR(c);
 }
 
 PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_init_pull)
@@ -3674,11 +3674,11 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_pull)
        if (crypto_secretstream_xchacha20poly1305_pull
                ((void *) state, (unsigned char *) ZSTR_VAL(msg), &msg_real_len, &tag,
                 c, (unsigned long long) c_len, ad, (unsigned long long) ad_len) != 0) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                RETURN_FALSE;
        }
        if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) {
-               zend_string_free(msg);
+               zend_string_efree(msg);
                zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0);
                return;
        }
index c3fb869e8e4fc60eefae323010e30ccfcc448da8..54da85c0b7e462875e0356d71bd1e485bd1fb9d9 100644 (file)
@@ -699,7 +699,7 @@ zend_string *php_base64_decode_ex_ssse3(const unsigned char *str, size_t length,
 # endif
 
        if (!php_base64_decode_impl(c, length, (unsigned char*)ZSTR_VAL(result), &outl, strict)) {
-               zend_string_free(result);
+               zend_string_efree(result);
                return NULL;
        }
 
@@ -722,7 +722,7 @@ zend_string *php_base64_decode_ex_ssse3(const unsigned char *str, size_t length,
        PHP_BASE64_DECODE_SSSE3_LOOP;
 
        if (!php_base64_decode_impl(c, length, (unsigned char*)ZSTR_VAL(result), &outl, strict)) {
-               zend_string_free(result);
+               zend_string_efree(result);
                return NULL;
        }
 
@@ -767,7 +767,7 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t length
        result = zend_string_alloc(length, 0);
 
        if (!php_base64_decode_impl(str, length, (unsigned char*)ZSTR_VAL(result), &outl, strict)) {
-               zend_string_free(result);
+               zend_string_efree(result);
                return NULL;
        }
 
index 740e7333ed6bc34f107aeadf8345b53b111619d1..85aa81f873c89e98c20fd9142b6425c4ddf1de6a 100644 (file)
@@ -5618,7 +5618,7 @@ PHP_FUNCTION(restore_include_path)
        }
        key = zend_string_init("include_path", sizeof("include_path")-1, 0);
        zend_restore_ini_entry(key, PHP_INI_STAGE_RUNTIME);
-       zend_string_free(key);
+       zend_string_efree(key);
 }
 /* }}} */
 
index bb497616e046647b4bcd83bba5fe3b0cdd983fe5..096d70e12c8083fda5817ab9604d490ce4194c7e 100644 (file)
@@ -1047,7 +1047,7 @@ PHPAPI PHP_FUNCTION(fgets)
 
                str = zend_string_alloc(len, 0);
                if (php_stream_get_line(stream, ZSTR_VAL(str), len, &line_len) == NULL) {
-                       zend_string_free(str);
+                       zend_string_efree(str);
                        RETURN_FALSE;
                }
                /* resize buffer if it's much larger than the result.
index f911b343882612351b91649cf330efad3a88b79e..3e3f269c041a9407413f16d85cdaaa808a853145 100644 (file)
@@ -1294,7 +1294,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(unsigned char *old, size_t oldle
                                len += replacement_len;
                                continue;
                        } else {
-                               zend_string_free(replaced);
+                               zend_string_efree(replaced);
                                return ZSTR_EMPTY_ALLOC();
                        }
                } else { /* SUCCESS */
index f0c8bcfd7b56bef5328802bd18f07fb1c1ebb258..5c5892e6b638d085275838e2ccc9f7ab9a085551 100644 (file)
@@ -257,7 +257,7 @@ static void php_print_gpcse_array(char *name, uint32_t name_length)
                        }
                } ZEND_HASH_FOREACH_END();
        }
-       zend_string_free(key);
+       zend_string_efree(key);
 }
 /* }}} */
 
index 85a5bb4475c88c5770b6e1b1dfb6c130b1d73d5f..5a6c422a4a2c16c1ac59f8d7d81d9738f9f59a9c 100644 (file)
@@ -229,7 +229,7 @@ PHP_FUNCTION(iptcembed)
        if (php_iptc_get1(fp, spool, poi?&poi:0) != 0xFF) {
                fclose(fp);
                if (spoolbuf) {
-                       zend_string_free(spoolbuf);
+                       zend_string_efree(spoolbuf);
                }
                RETURN_FALSE;
        }
@@ -237,7 +237,7 @@ PHP_FUNCTION(iptcembed)
        if (php_iptc_get1(fp, spool, poi?&poi:0) != 0xD8) {
                fclose(fp);
                if (spoolbuf) {
-                       zend_string_free(spoolbuf);
+                       zend_string_efree(spoolbuf);
                }
                RETURN_FALSE;
        }
index f4def94e01c36823020f942690d2add86a5991cc..d1e78dcc7a9f7e45a86b87ecd552ba5fe5992099 100644 (file)
@@ -56,7 +56,7 @@ PHPAPI zend_string* php_inet_ntop(const struct sockaddr *addr) {
                                ZSTR_LEN(ret) = strlen(ZSTR_VAL(ret));
                                return ret;
                        }
-                       zend_string_free(ret);
+                       zend_string_efree(ret);
                        break;
                }
 #endif
@@ -66,7 +66,7 @@ PHPAPI zend_string* php_inet_ntop(const struct sockaddr *addr) {
                                ZSTR_LEN(ret) = strlen(ZSTR_VAL(ret));
                                return ret;
                        }
-                       zend_string_free(ret);
+                       zend_string_efree(ret);
                        break;
                }
        }
@@ -88,7 +88,7 @@ PHPAPI zend_string* php_inet_ntop(const struct sockaddr *addr) {
                                ZSTR_LEN(ret) = strlen(ZSTR_VAL(ret));
                                return ret;
                        }
-                       zend_string_free(ret);
+                       zend_string_efree(ret);
                        break;
                }
        }
index dff62f6d8e8d6a545f7d1a0d594a38e1d0e06f6e..105abbc56552e2a246be165bd0b9686396ddda38 100644 (file)
@@ -544,13 +544,13 @@ PHP_FUNCTION(password_hash)
                                zend_string_release(salt);
 
                                if (status != ARGON2_OK) {
-                                       zend_string_free(encoded);
+                                       zend_string_efree(encoded);
                                        php_error_docref(NULL, E_WARNING, "%s", argon2_error_message(status));
                                        RETURN_FALSE;
                                }
 
                                ZSTR_VAL(encoded)[ZSTR_LEN(encoded)] = 0;
-                               RETURN_STR(encoded);
+                               RETURN_NEW_STR(encoded);
                        }
                        break;
 #endif
index fa82e74874293c364d91c202f16bd8861950293c..d3f0c1cd7c8e7b70d2ab24746f44db332e9e877c 100644 (file)
@@ -419,7 +419,7 @@ PHP_FUNCTION(stream_socket_recvfrom)
                RETURN_NEW_STR(read_buf);
        }
 
-       zend_string_free(read_buf);
+       zend_string_efree(read_buf);
        RETURN_FALSE;
 }
 /* }}} */
index 0f6780fff03bdcbe085a49c690c1c34eafd21936..f43d44929bb53108e69dfd706d960d48da7b41d9 100644 (file)
@@ -164,7 +164,7 @@ static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen)
                if (EXPECTED((((c ^ '0') - 10) >> (8 * sizeof(unsigned int) - 1)) | is_letter)) {
                        d = (l - 0x10 - 0x27 * is_letter) << 4;
                } else {
-                       zend_string_free(str);
+                       zend_string_efree(str);
                        return NULL;
                }
                c = old[j++];
@@ -173,7 +173,7 @@ static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen)
                if (EXPECTED((((c ^ '0') - 10) >> (8 * sizeof(unsigned int) - 1)) | is_letter)) {
                        d |= l - 0x10 - 0x27 * is_letter;
                } else {
-                       zend_string_free(str);
+                       zend_string_efree(str);
                        return NULL;
                }
                ret[i] = d;
@@ -1666,7 +1666,7 @@ PHP_FUNCTION(dirname)
 #endif
        } else if (levels < 1) {
                php_error_docref(NULL, E_WARNING, "Invalid argument, levels must be >= 1");
-               zend_string_free(ret);
+               zend_string_efree(ret);
                return;
        } else {
                /* Some levels up */
@@ -6025,7 +6025,7 @@ PHP_FUNCTION(money_format)
 
        str = zend_string_safe_alloc(format_len, 1, 1024, 0);
        if ((res_len = strfmon(ZSTR_VAL(str), ZSTR_LEN(str), format, value)) < 0) {
-               zend_string_free(str);
+               zend_string_efree(str);
                RETURN_FALSE;
        }
 #ifdef _AIX
index 74fc2503036eb12c93d290b29ecdc37cb507a489..e9714d28e18eb69505730ec3b65378405696f063 100644 (file)
@@ -192,7 +192,7 @@ PHPAPI zend_string *php_uudecode(char *src, size_t src_len) /* {{{ */
        return dest;
 
 err:
-       zend_string_free(dest);
+       zend_string_efree(dest);
 
        return NULL;
 }
index aa632d04f10c1de994eb313aa6b61cd6aa09f85e..b6b3f57db13b1150514d39d082565562a2249001 100644 (file)
@@ -252,13 +252,13 @@ static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t
        unsigned char *end = *(unsigned char **)p+maxlen;
 
        if (end < *p) {
-               zend_string_free(str);
+               zend_string_efree(str);
                return NULL;
        }
 
        for (i = 0; i < len; i++) {
                if (*p >= end) {
-                       zend_string_free(str);
+                       zend_string_efree(str);
                        return NULL;
                }
                if (**p != '\\') {
@@ -275,7 +275,7 @@ static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t
                                } else if (**p >= 'A' && **p <= 'F') {
                                        ch = (ch << 4) + (**p -'A'+10);
                                } else {
-                                       zend_string_free(str);
+                                       zend_string_efree(str);
                                        return NULL;
                                }
                        }
@@ -1341,7 +1341,7 @@ yy80:
        }
 
        if (*(YYCURSOR) != '"') {
-               zend_string_free(str);
+               zend_string_efree(str);
                *p = YYCURSOR;
                return 0;
        }
index 6606ebe00998bb71f5406db0cdeeb78c052738d1..8e238dae6e0da1ba98180fed14e6fe35d8d7642d 100644 (file)
@@ -250,13 +250,13 @@ static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t
        unsigned char *end = *(unsigned char **)p+maxlen;
 
        if (end < *p) {
-               zend_string_free(str);
+               zend_string_efree(str);
                return NULL;
        }
 
        for (i = 0; i < len; i++) {
                if (*p >= end) {
-                       zend_string_free(str);
+                       zend_string_efree(str);
                        return NULL;
                }
                if (**p != '\\') {
@@ -273,7 +273,7 @@ static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t
                                } else if (**p >= 'A' && **p <= 'F') {
                                        ch = (ch << 4) + (**p -'A'+10);
                                } else {
-                                       zend_string_free(str);
+                                       zend_string_efree(str);
                                        return NULL;
                                }
                        }
@@ -848,7 +848,7 @@ use_double:
        }
 
        if (*(YYCURSOR) != '"') {
-               zend_string_free(str);
+               zend_string_efree(str);
                *p = YYCURSOR;
                return 0;
        }
index afb033f130be7c02cb5e937b556f609c053891ce..815f64ecb44f9fab9e166a254ddb5500641defbd 100644 (file)
@@ -1328,7 +1328,7 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_read)
                        ZSTR_LEN(buffer) = n;
                        RETURN_NEW_STR(buffer);
                } else {
-                       zend_string_free(buffer);
+                       zend_string_efree(buffer);
                        RETURN_EMPTY_STRING()
                }
        } else {
@@ -2860,7 +2860,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
        buffer = zend_string_safe_alloc(1, len, 0, 0);
        n = zip_fread(zf, ZSTR_VAL(buffer), ZSTR_LEN(buffer));
        if (n < 1) {
-               zend_string_free(buffer);
+               zend_string_efree(buffer);
                RETURN_EMPTY_STRING();
        }
 
index fde9f02ffaa0c2236448a93dde56ef2e61e45215..dd38fa685783e60b38a6f19bebd8985bd7422473 100644 (file)
@@ -362,7 +362,7 @@ static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encod
                        ZSTR_VAL(out)[ZSTR_LEN(out)] = '\0';
                        return out;
                } else {
-                       zend_string_free(out);
+                       zend_string_efree(out);
                }
        }
 
index 9e7f185bd944715b11d3e69005b533b99b983d65..09e5afcf3bbbe99705eb968c0a32cca7d177b820 100644 (file)
@@ -600,7 +600,7 @@ PHPAPI void php_build_argv(char *s, zval *track_vars_array)
                for (i = 0; i < SG(request_info).argc; i++) {
                        ZVAL_STRING(&tmp, SG(request_info).argv[i]);
                        if (zend_hash_next_index_insert(Z_ARRVAL(arr), &tmp) == NULL) {
-                               zend_string_free(Z_STR(tmp));
+                               zend_string_efree(Z_STR(tmp));
                        }
                }
        } else  if (s && *s) {
@@ -614,7 +614,7 @@ PHPAPI void php_build_argv(char *s, zval *track_vars_array)
                        ZVAL_STRING(&tmp, ss);
                        count++;
                        if (zend_hash_next_index_insert(Z_ARRVAL(arr), &tmp) == NULL) {
-                               zend_string_free(Z_STR(tmp));
+                               zend_string_efree(Z_STR(tmp));
                        }
                        if (space) {
                                *space = '+';