diff options
| author | Carlos Martín Nieto <cmn@elego.de> | 2011-07-05 15:09:17 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@elego.de> | 2011-07-05 15:28:35 +0200 |
| commit | 2ee318a7bc5f7e975e31ca03d0e275fa3619633e (patch) | |
| tree | 72c68cf964f87c2446ea6bebacc99a1e23204308 /src/odb_pack.c | |
| parent | d830919a2cdd59ad9f9d0e9b44b7a6a0e331799c (diff) | |
| download | libgit2-2ee318a7bc5f7e975e31ca03d0e275fa3619633e.tar.gz | |
Small fixes in pack_window_open
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 <cmn@elego.de>
Diffstat (limited to 'src/odb_pack.c')
| -rw-r--r-- | src/odb_pack.c | 7 |
1 files changed, 6 insertions, 1 deletions
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++; |
