Skip to content

Commit

Permalink
fix memory leaks relate to SAP_UC* handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gkralik committed Feb 15, 2016
1 parent a3a8ab3 commit 45c68c6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions rfc_parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions sapnwrfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -429,15 +430,16 @@ 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) {
zend_replace_error_handling(EH_NORMAL, NULL, NULL);
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);
Expand Down

0 comments on commit 45c68c6

Please sign in to comment.