diff options
author | Tatsuya Kinoshita <tats@debian.org> | 2021-03-03 22:03:18 +0000 |
---|---|---|
committer | Tatsuya Kinoshita <tats@debian.org> | 2021-03-03 22:03:18 +0000 |
commit | 91731ec385b800431677f6a9da4815e24cbaaa37 (patch) | |
tree | fb9552b3f12a2621fd54b80e6c5f283a2f89ed34 | |
parent | Update ChangeLog (diff) | |
download | w3m-91731ec385b800431677f6a9da4815e24cbaaa37.tar.gz w3m-91731ec385b800431677f6a9da4815e24cbaaa37.zip |
Prevent unneeded memory allocation in Strgrow
-rw-r--r-- | Str.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -288,13 +288,15 @@ Strgrow(Str x) if (x->length + 1 >= newlen) x->length = newlen - 2; } - x->ptr = GC_MALLOC_ATOMIC(newlen); - if (x->ptr == NULL) - exit(1); - x->area_size = newlen; - bcopy((void *)old, (void *)x->ptr, x->length); + if (x->area_size < newlen) { + x->ptr = GC_MALLOC_ATOMIC(newlen); + if (x->ptr == NULL) + exit(1); + x->area_size = newlen; + bcopy((void *)old, (void *)x->ptr, x->length); + GC_free(old); + } x->ptr[x->length] = '\0'; - GC_free(old); } Str |