curl-library
[PATCH 2/4] src/mkhelp: use stack allocation instead of heap for line buffer
From: Dave Reisner <d_at_falconindy.com>
Date: Mon, 6 May 2013 14:19:49 -0400
Date: Mon, 6 May 2013 14:19:49 -0400
$ bloat-o-meter curl.before curl.after
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-29 (-29)
function old new delta
hugehelp 212 183 -29
---
src/mkhelp.pl | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/src/mkhelp.pl b/src/mkhelp.pl
index 444b669..faa3a3b 100644
--- a/src/mkhelp.pl
+++ b/src/mkhelp.pl
@@ -179,7 +179,7 @@ static void zfree_func(voidpf opaque, voidpf ptr)
/* Decompress and send to stdout a gzip-compressed buffer */
void hugehelp(void)
{
- unsigned char* buf;
+ unsigned char buf[BUF_SIZE];
int status,headerlen;
z_stream z;
@@ -197,21 +197,17 @@ void hugehelp(void)
if (inflateInit2(&z, -MAX_WBITS) != Z_OK)
return;
- buf = malloc(BUF_SIZE);
- if (buf) {
- while(1) {
- z.avail_out = BUF_SIZE;
- z.next_out = buf;
- status = inflate(&z, Z_SYNC_FLUSH);
- if (status == Z_OK || status == Z_STREAM_END) {
- fwrite(buf, BUF_SIZE - z.avail_out, 1, stdout);
- if (status == Z_STREAM_END)
- break;
- }
- else
- break; /* Error */
+ while(1) {
+ z.avail_out = BUF_SIZE;
+ z.next_out = buf;
+ status = inflate(&z, Z_SYNC_FLUSH);
+ if (status == Z_OK || status == Z_STREAM_END) {
+ fwrite(buf, BUF_SIZE - z.avail_out, 1, stdout);
+ if (status == Z_STREAM_END)
+ break;
}
- free(buf);
+ else
+ break; /* Error */
}
inflateEnd(&z);
}
--
1.8.2.2
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-05-06