Wrap inflate and other zlib routines for better error reporting
R. Tyler Ballance reported a mysterious transient repository corruption; after much digging, it turns out that we were not catching and reporting memory allocation errors from some calls we make to zlib. This one _just_ wraps things; it doesn't do the "retry on low memory error" part, at least not yet. It is an independent issue from the reporting. Some of the errors are expected and passed back to the caller, but we die when zlib reports it failed to allocate memory for now. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
141201d124
commit
39c68542fc
@ -82,7 +82,7 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
|
||||
do {
|
||||
obj_req->stream.next_out = expn;
|
||||
obj_req->stream.avail_out = sizeof(expn);
|
||||
obj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH);
|
||||
obj_req->zret = git_inflate(&obj_req->stream, Z_SYNC_FLUSH);
|
||||
SHA1_Update(&obj_req->c, expn,
|
||||
sizeof(expn) - obj_req->stream.avail_out);
|
||||
} while (obj_req->stream.avail_in && obj_req->zret == Z_OK);
|
||||
@ -142,7 +142,7 @@ static void start_object_request(struct walker *walker,
|
||||
|
||||
memset(&obj_req->stream, 0, sizeof(obj_req->stream));
|
||||
|
||||
inflateInit(&obj_req->stream);
|
||||
git_inflate_init(&obj_req->stream);
|
||||
|
||||
SHA1_Init(&obj_req->c);
|
||||
|
||||
@ -183,7 +183,7 @@ static void start_object_request(struct walker *walker,
|
||||
file; also rewind to the beginning of the local file. */
|
||||
if (prev_read == -1) {
|
||||
memset(&obj_req->stream, 0, sizeof(obj_req->stream));
|
||||
inflateInit(&obj_req->stream);
|
||||
git_inflate_init(&obj_req->stream);
|
||||
SHA1_Init(&obj_req->c);
|
||||
if (prev_posn>0) {
|
||||
prev_posn = 0;
|
||||
@ -243,7 +243,7 @@ static void finish_object_request(struct object_request *obj_req)
|
||||
return;
|
||||
}
|
||||
|
||||
inflateEnd(&obj_req->stream);
|
||||
git_inflate_end(&obj_req->stream);
|
||||
SHA1_Final(obj_req->real_sha1, &obj_req->c);
|
||||
if (obj_req->zret != Z_STREAM_END) {
|
||||
unlink(obj_req->tmpfile);
|
||||
|
Reference in New Issue
Block a user