From 45c68c68059eb31e0d8106bf2a15ecb3f8845560 Mon Sep 17 00:00:00 2001 From: Gregor Kralik Date: Mon, 15 Feb 2016 19:00:23 +0100 Subject: [PATCH] fix memory leaks relate to SAP_UC* handling --- CHANGELOG.md | 3 ++- rfc_parameters.c | 3 +-- sapnwrfc.c | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8847a89..d449056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ All notable changes to this project will be documented in this file. - Update some of the documentation to reflect current development state ### Fixed -- Memory leaks releated to zend_string handling throughout the extension +- Memory leaks related to zend_string handling throughout the extension +- Memory leaks related to SAP_UC* handling throughout the extension ### Removed - References to TSRM; they are not needed anymore in PHP7 diff --git a/rfc_parameters.c b/rfc_parameters.c index 1621f57..76edd44 100644 --- a/rfc_parameters.c +++ b/rfc_parameters.c @@ -66,7 +66,7 @@ rfc_set_value_return_t rfc_set_date_value(DATA_CONTAINER_HANDLE h, SAP_UC *name, } value_u = zval_to_sapuc(value); - memcpy((char *)value_date, (char *)value_u, 16); + memcpy((char *)value_date, (char *)value_u, SAP_DATE_LN * 2); free((char *)value_u); rc = RfcSetDate(h, name, value_date, &error_info); @@ -205,7 +205,6 @@ rfc_set_value_return_t rfc_set_num_value(DATA_CONTAINER_HANDLE h, SAP_UC *name, } value_u = zval_to_sapuc(value); - rc = RfcSetNum(h, name, (RFC_NUM *)value_u, strlenU(value_u), &error_info); free((char *)value_u); diff --git a/sapnwrfc.c b/sapnwrfc.c index 7c5e497..371ef89 100644 --- a/sapnwrfc.c +++ b/sapnwrfc.c @@ -196,6 +196,7 @@ static void sapnwrfc_open_connection(sapnwrfc_connection_object *intern, zval *c ZEND_HASH_FOREACH_STR_KEY_VAL(connection_params_hash, key, val) { if (key) { // is string + // those are free'd in sapnwrfc_connection_object_free intern->rfc_login_params[i].name = zend_string_to_sapuc(key); intern->rfc_login_params[i].value = zval_to_sapuc(val); @@ -429,6 +430,7 @@ PHP_METHOD(Connection, setIniPath) RFC_ERROR_INFO error_info; RFC_RC rc = RFC_OK; zend_string *path; + SAP_UC *path_u; zend_replace_error_handling(EH_THROW, sapnwrfc_connection_exception_ce, NULL); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &path) == FAILURE) { @@ -436,8 +438,8 @@ PHP_METHOD(Connection, setIniPath) return; } - // FIXME assign path in call and free after + check other similar cases - rc = RfcSetIniPath(zend_string_to_sapuc(path), &error_info); + rc = RfcSetIniPath((path_u = zend_string_to_sapuc(path)), &error_info); + free((char *)path_u); if (rc != RFC_OK) { sapnwrfc_throw_connection_exception(error_info, "Failed to set INI file path"); zend_replace_error_handling(EH_NORMAL, NULL, NULL);