diff --git a/mosquitto.c b/mosquitto.c index 8e47fe2..be64b47 100644 --- a/mosquitto.c +++ b/mosquitto.c @@ -117,7 +117,11 @@ PHP_METHOD(Mosquitto_Client, __construct) if (!object->client) { char *message = php_mosquitto_strerror_wrapper(errno); zend_throw_exception(mosquitto_ce_exception, message, 1 TSRMLS_CC); - efree(message); +#ifndef STRERROR_R_CHAR_P + if (message != NULL) { + efree(message); + } +#endif } } /* }}} */ @@ -835,10 +839,11 @@ static int strerror_r(int errnum, char *buf, size_t buf_len) PHP_MOSQUITTO_API char *php_mosquitto_strerror_wrapper(int err) { - char *buf = ecalloc(256, sizeof(char)); + char *buf; #ifdef STRERROR_R_CHAR_P return strerror_r(err, buf, 256); #else + buf = ecalloc(256, sizeof(char)); if (!strerror_r(err, buf, 256)) { return buf; } diff --git a/travis/run-tests.sh b/travis/run-tests.sh index dabee72..3bbe974 100755 --- a/travis/run-tests.sh +++ b/travis/run-tests.sh @@ -9,4 +9,4 @@ cd tests mosquitto -c mosquitto.conf -d cd .. -REPORT_EXIT_STATUS=1 TEST_PHP_ARGS="-q --show-diff" make test +USE_ZEND_ALLOC=1 REPORT_EXIT_STATUS=1 TEST_PHP_ARGS="-q --show-diff" make test