From 2ee318a7bc5f7e975e31ca03d0e275fa3619633e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 5 Jul 2011 15:09:17 +0200 Subject: [PATCH] Small fixes in pack_window_open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check if the window structure has actually been allocated before trying to access it, and don't leak said structure if the map fails. Signed-off-by: Carlos Martín Nieto --- src/odb_pack.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/odb_pack.c b/src/odb_pack.c index 59661a662..44604ef91 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -480,6 +480,9 @@ static unsigned char *pack_window_open( size_t len; win = git__calloc(1, sizeof(*win)); + if (win == NULL) + return NULL; + win->offset = (offset / window_align) * window_align; len = (size_t)(p->pack_size - win->offset); @@ -492,8 +495,10 @@ static unsigned char *pack_window_open( pack_window_close_lru(backend, p, p->pack_fd) == GIT_SUCCESS) {} if (git_futils_mmap_ro(&win->window_map, p->pack_fd, - win->offset, len) < GIT_SUCCESS) + win->offset, len) < GIT_SUCCESS) { + free(win); return NULL; + } backend->mmap_calls++; backend->open_windows++;