summaryrefslogtreecommitdiff
path: root/vio
diff options
context:
space:
mode:
authorDavi Arnaut <Davi.Arnaut@Sun.COM>2010-07-08 18:20:08 -0300
committerDavi Arnaut <Davi.Arnaut@Sun.COM>2010-07-08 18:20:08 -0300
commita10ae35328ec800eff63c0bbb06d279e44c0a5a1 (patch)
tree6c88c3c07b30acb464ca8bf81bbef916216da616 /vio
parentd4cd1f843da60019664dfad2b0ad6987f82f01c6 (diff)
downloadmariadb-git-a10ae35328ec800eff63c0bbb06d279e44c0a5a1.tar.gz
Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled
Essentially, the problem is that safemalloc is excruciatingly slow as it checks all allocated blocks for overrun at each memory management primitive, yielding a almost exponential slowdown for the memory management functions (malloc, realloc, free). The overrun check basically consists of verifying some bytes of a block for certain magic keys, which catches some simple forms of overrun. Another minor problem is violation of aliasing rules and that its own internal list of blocks is prone to corruption. Another issue with safemalloc is rather the maintenance cost as the tool has a significant impact on the server code. Given the magnitude of memory debuggers available nowadays, especially those that are provided with the platform malloc implementation, maintenance of a in-house and largely obsolete memory debugger becomes a burden that is not worth the effort due to its slowness and lack of support for detecting more common forms of heap corruption. Since there are third-party tools that can provide the same functionality at a lower or comparable performance cost, the solution is to simply remove safemalloc. Third-party tools can provide the same functionality at a lower or comparable performance cost. The removal of safemalloc also allows a simplification of the malloc wrappers, removing quite a bit of kludge: redefinition of my_malloc, my_free and the removal of the unused second argument of my_free. Since free() always check whether the supplied pointer is null, redudant checks are also removed. Also, this patch adds unit testing for my_malloc and moves my_realloc implementation into the same file as the other memory allocation primitives.
Diffstat (limited to 'vio')
-rw-r--r--vio/test-ssl.c24
-rw-r--r--vio/test-sslclient.c6
-rw-r--r--vio/test-sslserver.c4
-rw-r--r--vio/vio.c6
-rw-r--r--vio/viosslfactories.c10
-rw-r--r--vio/viotest-ssl.c24
6 files changed, 37 insertions, 37 deletions
diff --git a/vio/test-ssl.c b/vio/test-ssl.c
index 855dc5fbb3e..25a394a1ce0 100644
--- a/vio/test-ssl.c
+++ b/vio/test-ssl.c
@@ -106,8 +106,8 @@ main(int argc, char** argv)
child_pid = fork();
if (child_pid==-1) {
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
fatal_error("fork");
}
if (child_pid==0)
@@ -116,28 +116,28 @@ main(int argc, char** argv)
char xbuf[100];
int r = vio_read(client_vio,xbuf, sizeof(xbuf));
if (r<=0) {
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
fatal_error("client:SSL_read");
}
xbuf[r] = 0;
printf("client:got %s\n", xbuf);
- my_free((uchar*)client_vio,MYF(0));
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(client_vio);
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
}
else
{
const char* s = "Huhuhuh";
int r = vio_write(server_vio,(uchar*)s, strlen(s));
if (r<=0) {
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
fatal_error("server:SSL_write");
}
- my_free((uchar*)server_vio,MYF(0));
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(server_vio);
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
}
return 0;
}
diff --git a/vio/test-sslclient.c b/vio/test-sslclient.c
index e1b8461397b..643dcbf2c8e 100644
--- a/vio/test-sslclient.c
+++ b/vio/test-sslclient.c
@@ -84,13 +84,13 @@ main( int argc __attribute__((unused)),
sslconnect(ssl_connector,client_vio,60L);
err = vio_read(client_vio,xbuf, sizeof(xbuf));
if (err<=0) {
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(ssl_connector);
fatal_error("client:SSL_read");
}
xbuf[err] = 0;
printf("client:got %s\n", xbuf);
- my_free((uchar*)client_vio,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(client_vio);
+ my_free(ssl_connector);
return 0;
}
#else /* HAVE_OPENSSL */
diff --git a/vio/test-sslserver.c b/vio/test-sslserver.c
index f55b5bae53a..3123a4def2c 100644
--- a/vio/test-sslserver.c
+++ b/vio/test-sslserver.c
@@ -139,12 +139,12 @@ main(int argc __attribute__((unused)), char** argv)
#if 0
if (err<=0) {
- my_free((uchar*)ssl_acceptor,MYF(0));
+ my_free(ssl_acceptor);
fatal_error("server:SSL_write");
}
#endif /* 0 */
- my_free((uchar*)ssl_acceptor,MYF(0));
+ my_free(ssl_acceptor);
return 0;
}
#else /* HAVE_OPENSSL */
diff --git a/vio/vio.c b/vio/vio.c
index 73dd68b938f..67704a56b22 100644
--- a/vio/vio.c
+++ b/vio/vio.c
@@ -164,7 +164,7 @@ static void vio_init(Vio* vio, enum enum_vio_type type,
void vio_reset(Vio* vio, enum enum_vio_type type,
my_socket sd, HANDLE hPipe, uint flags)
{
- my_free(vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(vio->read_buffer);
vio_init(vio, type, sd, hPipe, flags);
}
@@ -263,8 +263,8 @@ void vio_delete(Vio* vio)
if (vio->type != VIO_CLOSED)
vio->vioclose(vio);
- my_free((uchar*) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
- my_free((uchar*) vio,MYF(0));
+ my_free(vio->read_buffer);
+ my_free(vio);
}
diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c
index d0a0a69f70b..2a38bbdfd57 100644
--- a/vio/viosslfactories.c
+++ b/vio/viosslfactories.c
@@ -224,7 +224,7 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
*error= SSL_INITERR_MEMFAIL;
DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
report_errors();
- my_free((void*)ssl_fd,MYF(0));
+ my_free(ssl_fd);
DBUG_RETURN(0);
}
@@ -240,7 +240,7 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
report_errors();
SSL_CTX_free(ssl_fd->ssl_context);
- my_free((void*)ssl_fd,MYF(0));
+ my_free(ssl_fd);
DBUG_RETURN(0);
}
@@ -254,7 +254,7 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
report_errors();
SSL_CTX_free(ssl_fd->ssl_context);
- my_free((void*)ssl_fd,MYF(0));
+ my_free(ssl_fd);
DBUG_RETURN(0);
}
}
@@ -264,7 +264,7 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
DBUG_PRINT("error", ("vio_set_cert_stuff failed"));
report_errors();
SSL_CTX_free(ssl_fd->ssl_context);
- my_free((void*)ssl_fd,MYF(0));
+ my_free(ssl_fd);
DBUG_RETURN(0);
}
@@ -344,6 +344,6 @@ new_VioSSLAcceptorFd(const char *key_file, const char *cert_file,
void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd)
{
SSL_CTX_free(fd->ssl_context);
- my_free((uchar*) fd, MYF(0));
+ my_free(fd);
}
#endif /* HAVE_OPENSSL */
diff --git a/vio/viotest-ssl.c b/vio/viotest-ssl.c
index b8abbac4ed6..5c68e861d2a 100644
--- a/vio/viotest-ssl.c
+++ b/vio/viotest-ssl.c
@@ -106,8 +106,8 @@ int main(int argc, char **argv)
child_pid = fork();
if (child_pid==-1)
{
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
fatal_error("fork");
}
if (child_pid==0)
@@ -116,15 +116,15 @@ int main(int argc, char **argv)
char xbuf[100];
int r = vio_ssl_read(client_vio,xbuf, sizeof(xbuf));
if (r<=0) {
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
fatal_error("client:SSL_read");
}
xbuf[r] = 0;
printf("client:got %s\n", xbuf);
- my_free((uchar*)client_vio,MYF(0));
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(client_vio);
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
sleep(1);
}
else
@@ -132,13 +132,13 @@ int main(int argc, char **argv)
const char* s = "Huhuhuh";
int r = vio_ssl_write(server_vio,(uchar*)s, strlen(s));
if (r<=0) {
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
fatal_error("server:SSL_write");
}
- my_free((uchar*)server_vio,MYF(0));
- my_free((uchar*)ssl_acceptor,MYF(0));
- my_free((uchar*)ssl_connector,MYF(0));
+ my_free(server_vio);
+ my_free(ssl_acceptor);
+ my_free(ssl_connector);
sleep(1);
}
return 0;