1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

decompress_data: change initial malloc size, drop init variable

Adjust the size of to_read for the initial read instead of setting the init
flag and using that later to check whether to read a smaller amount than
the value in to_read. This also affects the realloc call on the initial
read, which was allocating more memory than necessary (altho this
discrepency would be corrected with the realloc for the next read).
This commit is contained in:
Miciah Dashiel Butler Masters 2006-11-05 04:21:52 +00:00 committed by Miciah Dashiel Butler Masters
parent e441361f2c
commit 6f8f41e20d

View File

@ -993,7 +993,6 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
do {
int to_read;
int init = 0;
if (state == NORMAL) {
/* ... we aren't finishing yet. */
@ -1037,14 +1036,17 @@ decompress_data(struct connection *conn, unsigned char *data, int len,
if (!conn->stream) return NULL;
/* On "startup" pipe is treated with care, but if everything
* was already written to the pipe, caution isn't necessary */
if (state != FINISHING) init = 1;
if (state != FINISHING) {
/* on init don't read too much */
to_read = PIPE_BUF / 32;
}
}
output = (unsigned char *) mem_realloc(output, *new_len + to_read);
if (!output) break;
did_read = read_encoded(conn->stream, output + *new_len,
init ? PIPE_BUF / 32 : to_read); /* on init don't read too much */
to_read);
if (did_read > 0) *new_len += did_read;
else if (did_read == -1) {
mem_free_set(&output, NULL);