You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ilya V. Matveychikov" <ma...@gmail.com> on 2016/05/30 13:38:16 UTC
[PATCH] ab: fix various memory leaks
This fixes memory leakage while running a big number of iterations.
Signed-off-by: Ilya V. Matveychikov <ma...@gmail.com>
---
support/ab.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/support/ab.c b/support/ab.c
index 46fa3b8..cbc428e 100644
--- a/support/ab.c
+++ b/support/ab.c
@@ -333,7 +333,7 @@ int err_response = 0; /* requests with invalid or
non-200 response */
int is_ssl;
SSL_CTX *ssl_ctx;
char *ssl_cipher = NULL;
-char *ssl_info = NULL;
+char ssl_info[128] = { 0 };
BIO *bio_out,*bio_err;
#endif
@@ -403,6 +403,11 @@ static void *xmalloc(size_t size)
return ret;
}
+static void xfree(void *ptr)
+{
+ free(ptr);
+}
+
static void *xcalloc(size_t num, size_t size)
{
void *ret = calloc(num, size);
@@ -654,7 +659,7 @@ static void ssl_proceed_handshake(struct connection *c)
case SSL_ERROR_NONE:
if (verbosity >= 2)
ssl_print_info(c);
- if (ssl_info == NULL) {
+ if (!ssl_info[0]) {
AB_SSL_CIPHER_CONST SSL_CIPHER *ci;
X509 *cert;
int sk_bits, pk_bits, swork;
@@ -667,8 +672,7 @@ static void ssl_proceed_handshake(struct connection *c)
else
pk_bits = 0; /* Anon DH */
- ssl_info = xmalloc(128);
- apr_snprintf(ssl_info, 128, "%s,%s,%d,%d",
+ apr_snprintf(ssl_info, sizeof(ssl_info), "%s,%s,%d,%d",
SSL_get_version(c->ssl),
SSL_CIPHER_get_name(ci),
pk_bits, sk_bits);
@@ -818,7 +822,7 @@ static void output_results(int sig)
printf("Server Hostname: %s\n", hostname);
printf("Server Port: %hu\n", port);
#ifdef USE_SSL
- if (is_ssl && ssl_info) {
+ if (is_ssl && ssl_info[0]) {
printf("SSL/TLS Protocol: %s\n", ssl_info);
}
#endif
@@ -1733,6 +1737,8 @@ static void test(void)
char *buff = xmalloc(postlen + reqlen + 1);
strcpy(buff, request);
memcpy(buff + reqlen, postdata, postlen);
+ if (request != _request)
+ xfree(request);
request = buff;
}
@@ -1882,6 +1888,9 @@ static void test(void)
output_html_results();
else
output_results(0);
+
+ xfree(stats);
+ xfree(con);
}
/* ------------------------------------------------------- */
@@ -2077,6 +2086,7 @@ static apr_status_t open_postfile(const char *pfile)
postlen = (apr_size_t)finfo.size;
postdata = xmalloc(postlen);
rv = apr_file_read_full(postfd, postdata, postlen, NULL);
+ xfree(postdata);
if (rv != APR_SUCCESS) {
fprintf(stderr, "ab: Could not read POST data file: %s\n",
apr_strerror(rv, errmsg, sizeof errmsg));
@@ -2413,5 +2423,15 @@ int main(int argc, const char * const argv[])
test();
apr_pool_destroy(cntxt);
+#ifdef USE_SSL
+ ERR_remove_state(0);
+ SSL_CTX_free(ssl_ctx);
+ BIO_free(bio_out);
+ BIO_free(bio_err);
+ ERR_free_strings();
+ CRYPTO_cleanup_all_ex_data();
+ SSL_COMP_free_compression_methods();
+ EVP_cleanup();
+#endif
return 0;
}
--
2.8.3