summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2001-08-07 07:30:17 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2001-08-07 07:30:17 +0000
commitdbf6c9afc21a9e22dc660f4686b8348a489d3e0e (patch)
tree29e795ce9d84279a706d37c4797bd0b1a6d267b3
parent751e12df434a2997311c278b751c235894641817 (diff)
downloadgnutls-dbf6c9afc21a9e22dc660f4686b8348a489d3e0e.tar.gz
realloc does not realloc memory if less size is requested.
-rw-r--r--lib/gnutls_mem.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/gnutls_mem.c b/lib/gnutls_mem.c
index 07c8e09c74..1c64409f26 100644
--- a/lib/gnutls_mem.c
+++ b/lib/gnutls_mem.c
@@ -77,6 +77,12 @@ opaque* ptr = _ptr;
void* gnutls_realloc( void* ptr, size_t size) {
void* ret;
+ if ( ptr != NULL && size <= _gnutls_malloc_ptr_size(ptr)) {
+ /* do nothing, just return the pointer.
+ * It's much faster.
+ */
+ return ptr;
+ }
ret = gnutls_malloc( size);
if (ret==NULL) return ret;
@@ -128,6 +134,12 @@ size_t _secure_ptr_size( svoid* ptr) {
svoid* secure_realloc( svoid* ptr, size_t size) {
svoid* ret;
+ if ( ptr != NULL && size <= _secure_ptr_size(ptr)) {
+ /* do not do realloc.
+ * return the previous pointer.
+ */
+ return ptr;
+ }
ret = secure_malloc( size);
if (ret==NULL) return ret;