Skip to content

Commit

Permalink
Free the error string if it's ours
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdm committed Mar 8, 2015
1 parent bdaa95e commit 3d9f726
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,15 @@ static zend_object_value mosquitto_client_object_new(zend_class_entry *ce TSRMLS

void php_mosquitto_handle_errno(int retval, int err TSRMLS_DC) {
const char *message;
int own_string = 0;

switch (retval) {
case MOSQ_ERR_SUCCESS:
return;

case MOSQ_ERR_ERRNO:
message = php_mosquitto_strerror_wrapper(errno);
own_string = 1;
break;

default:
Expand All @@ -902,6 +904,9 @@ void php_mosquitto_handle_errno(int retval, int err TSRMLS_DC) {
}

zend_throw_exception(mosquitto_ce_exception, (char *) message, 0 TSRMLS_CC);
if (own_string) {
efree((void *) message);
}
}

PHP_MOSQUITTO_API void php_mosquitto_connect_callback(struct mosquitto *mosq, void *obj, int rc)
Expand Down

0 comments on commit 3d9f726

Please sign in to comment.