Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
filebundle: do not use extra input buffer
  • Loading branch information
perexg committed Jan 23, 2015
1 parent 9508a68 commit 3feccf3
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/filebundle.c
Expand Up @@ -24,6 +24,7 @@
#include <string.h>
#include <stdio.h>
#if ENABLE_ZLIB
#define ZLIB_CONST 1
#include <zlib.h>
#endif
#include <sys/types.h>
Expand Down Expand Up @@ -78,18 +79,16 @@ static uint8_t *_fb_inflate ( const uint8_t *data, size_t size, size_t orig )
{
int err;
z_stream zstr;
uint8_t *bufin, *bufout;
uint8_t *bufout;

/* Setup buffers */
bufin = malloc(size);
bufout = malloc(orig);
memcpy(bufin, data, size);

/* Setup zlib */
memset(&zstr, 0, sizeof(zstr));
inflateInit2(&zstr, 31);
zstr.avail_in = size;
zstr.next_in = bufin;
zstr.next_in = data;
zstr.avail_out = orig;
zstr.next_out = bufout;

Expand All @@ -99,7 +98,6 @@ static uint8_t *_fb_inflate ( const uint8_t *data, size_t size, size_t orig )
free(bufout);
bufout = NULL;
}
free(bufin);
inflateEnd(&zstr);

return bufout;
Expand All @@ -111,18 +109,16 @@ static uint8_t *_fb_deflate ( const uint8_t *data, size_t orig, size_t *size )
{
int err;
z_stream zstr;
uint8_t *bufin, *bufout;
uint8_t *bufout;

/* Setup buffers */
bufin = malloc(orig);
bufout = malloc(orig);
memcpy(bufin, data, orig);

/* Setup zlib */
memset(&zstr, 0, sizeof(zstr));
err = deflateInit2(&zstr, 9, Z_DEFLATED, 31, 9, Z_DEFAULT_STRATEGY);
zstr.avail_in = orig;
zstr.next_in = bufin;
zstr.next_in = data;
zstr.avail_out = orig;
zstr.next_out = bufout;

Expand All @@ -147,7 +143,6 @@ static uint8_t *_fb_deflate ( const uint8_t *data, size_t orig, size_t *size )
}
break;
}
free(bufin);
deflateEnd(&zstr);

return bufout;
Expand Down

0 comments on commit 3feccf3

Please sign in to comment.