Skip to content

Commit

Permalink
Fix fd_hist check occurring too early on decompress.
Browse files Browse the repository at this point in the history
fsync after flushing buffer.
Remove unnecessary memset after anonymous mmap.
Do test malloc before compression backend to see how big a chunk can be passed.
  • Loading branch information
ckolivas committed Nov 2, 2010
1 parent c0ac813 commit 9c00229
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,13 @@ static void decompress_file(void)

if (!NO_SET_PERMS)
preserve_perms(fd_in, fd_out);
if (fd_hist == -1)
fatal("Failed to open history file %s\n", control.outfile);
} else
fd_out = open_tmpoutfile();

fd_hist = open(control.outfile, O_RDONLY);
if (fd_hist == -1)
fatal("Failed to open history file %s\n", control.outfile);

read_magic(fd_in, &expected_size);
print_progress("Decompressing...");

Expand Down
2 changes: 0 additions & 2 deletions rzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,6 @@ static void rzip_chunk(struct rzip_state *st, int fd_in, int fd_out, i64 offset,
continue;
}
print_maxverbose("Preallocated %lld ram...\n", prealloc_size);
if (!memset(buf, 0, prealloc_size))
fatal("Failed to memset in rzip_chunk\n");
if (!STDIN) {
/* STDIN will use this already allocated ram */
if (munmap(buf, prealloc_size) != 0)
Expand Down
14 changes: 14 additions & 0 deletions stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ void *open_stream_out(int f, int n, i64 limit)
{
unsigned cwindow = control.window;
struct stream_info *sinfo;
uchar *testmalloc;
int i;

sinfo = malloc(sizeof(*sinfo));
Expand Down Expand Up @@ -642,6 +643,18 @@ void *open_stream_out(int f, int n, i64 limit)
return NULL;
}

/* Find the largest we can make the window based on ability to malloc
* ram. We need enough for the 2 streams and for the compression
* backend at most, being conservative. */
retest_malloc:
testmalloc = malloc(sinfo->bufsize * (n + 1));
if (!testmalloc) {
sinfo->bufsize = sinfo->bufsize / 10 * 9;
goto retest_malloc;
}
free(testmalloc);
print_maxverbose("Succeeded to malloc for compression bufsize of %lld\n", sinfo->bufsize);

for (i = 0; i < n; i++) {
sinfo->s[i].buf = malloc(sinfo->bufsize);
if (!sinfo->s[i].buf)
Expand Down Expand Up @@ -783,6 +796,7 @@ static int flush_buffer(struct stream_info *sinfo, int stream)

if (write_buf(sinfo->fd, sinfo->s[stream].buf, c_len) != 0)
return -1;
fsync(sinfo->fd);
sinfo->cur_pos += c_len;

sinfo->s[stream].buflen = 0;
Expand Down

0 comments on commit 9c00229

Please sign in to comment.