fix missed inflateEnd call and enhance handling inflate return value
This commit is contained in:
parent
3ec80b7ac7
commit
afdcd9b7df
4 changed files with 33 additions and 35 deletions
|
@ -40,7 +40,6 @@
|
|||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <poll.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "net.h"
|
||||
#include "include.h"
|
||||
|
@ -1493,26 +1492,13 @@ void work_packed (struct connection *c, long long msg_id) {
|
|||
|
||||
int l = prefetch_strlen ();
|
||||
char *s = fetch_str (l);
|
||||
size_t dl = MAX_PACKED_SIZE;
|
||||
|
||||
z_stream strm;
|
||||
memset (&strm, 0, sizeof (strm));
|
||||
assert (inflateInit2 (&strm, 16 + MAX_WBITS) == Z_OK);
|
||||
strm.avail_in = l;
|
||||
strm.next_in = (void *)s;
|
||||
strm.avail_out = MAX_PACKED_SIZE;
|
||||
strm.next_out = (void *)buf;
|
||||
|
||||
int err = inflate (&strm, Z_FINISH);
|
||||
if (verbosity) {
|
||||
logprintf ( "inflate error = %d\n", err);
|
||||
logprintf ( "inflated %d bytes\n", (int)strm.total_out);
|
||||
}
|
||||
int total_out = tinflate (s, l, buf, MAX_PACKED_SIZE);
|
||||
int *end = in_ptr;
|
||||
int *eend = in_end;
|
||||
assert (dl % 4 == 0);
|
||||
//assert (total_out % 4 == 0);
|
||||
in_ptr = buf;
|
||||
in_end = in_ptr + strm.total_out / 4;
|
||||
in_end = in_ptr + total_out / 4;
|
||||
if (verbosity >= 4) {
|
||||
logprintf ( "Unzipped data: ");
|
||||
hexdump_in ();
|
||||
|
|
21
queries.c
21
queries.c
|
@ -20,7 +20,6 @@
|
|||
#include <string.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <zlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -215,26 +214,12 @@ void query_result (long long id UU) {
|
|||
fetch_int ();
|
||||
int l = prefetch_strlen ();
|
||||
char *s = fetch_str (l);
|
||||
size_t dl = MAX_PACKED_SIZE;
|
||||
|
||||
z_stream strm;
|
||||
memset (&strm, 0, sizeof (strm));
|
||||
assert (inflateInit2 (&strm, 16 + MAX_WBITS) == Z_OK);
|
||||
strm.avail_in = l;
|
||||
strm.next_in = (void *)s;
|
||||
strm.avail_out = MAX_PACKED_SIZE;
|
||||
strm.next_out = (void *)packed_buffer;
|
||||
|
||||
int err = inflate (&strm, Z_FINISH);
|
||||
if (verbosity) {
|
||||
logprintf ( "inflate error = %d\n", err);
|
||||
logprintf ( "inflated %d bytes\n", (int)strm.total_out);
|
||||
}
|
||||
int total_out = tinflate (s, l, packed_buffer, MAX_PACKED_SIZE);
|
||||
end = in_ptr;
|
||||
eend = in_end;
|
||||
assert (dl % 4 == 0);
|
||||
//assert (total_out % 4 == 0);
|
||||
in_ptr = packed_buffer;
|
||||
in_end = in_ptr + strm.total_out / 4;
|
||||
in_end = in_ptr + total_out / 4;
|
||||
if (verbosity >= 4) {
|
||||
logprintf ( "Unzipped data: ");
|
||||
hexdump_in ();
|
||||
|
|
26
tools.c
26
tools.c
|
@ -22,10 +22,13 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/err.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "interface.h"
|
||||
#include "tools.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
static void out_of_memory (void) {
|
||||
logprintf ("Out of memory\n");
|
||||
assert (0 && "Out of memory");
|
||||
|
@ -70,3 +73,26 @@ void ensure_ptr (void *p) {
|
|||
out_of_memory ();
|
||||
}
|
||||
}
|
||||
|
||||
int tinflate (void *input, int ilen, void *output, int olen) {
|
||||
z_stream strm;
|
||||
memset (&strm, 0, sizeof (strm));
|
||||
assert (inflateInit2 (&strm, 16 + MAX_WBITS) == Z_OK);
|
||||
strm.avail_in = ilen;
|
||||
strm.next_in = input;
|
||||
strm.avail_out = olen ;
|
||||
strm.next_out = output;
|
||||
int err = inflate (&strm, Z_FINISH), total_out = 0;
|
||||
if (err == Z_OK || err == Z_STREAM_END) {
|
||||
total_out = (int) strm.total_out;
|
||||
if (err == Z_STREAM_END && verbosity >= 2) {
|
||||
logprintf ( "inflated %d bytes\n", (int) strm.total_out);
|
||||
}
|
||||
}
|
||||
if (verbosity && err != Z_STREAM_END) {
|
||||
logprintf ( "inflate error = %d\n", err);
|
||||
logprintf ( "inflated %d bytes\n", (int) strm.total_out);
|
||||
}
|
||||
inflateEnd (&strm);
|
||||
return total_out;
|
||||
}
|
||||
|
|
1
tools.h
1
tools.h
|
@ -24,6 +24,7 @@ void *talloc (size_t size);
|
|||
void *trealloc (void *ptr, size_t size);
|
||||
void *talloc0 (size_t size);
|
||||
char *tstrdup (const char *s);
|
||||
int tinflate (void *input, int ilen, void *output, int olen);
|
||||
void ensure (int r);
|
||||
void ensure_ptr (void *p);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue