From d074928c0368b28905a9afbd7c040e95b91bbe8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 29 Dec 2010 20:05:24 +0000 Subject: [PATCH] Avoid leaking a file descriptor on error. Thanks PovAddict for running cppcheck. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40037 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/debugger/files/SourceFile.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/apps/debugger/files/SourceFile.cpp b/src/apps/debugger/files/SourceFile.cpp index 479c0141b2..001dcf0e76 100644 --- a/src/apps/debugger/files/SourceFile.cpp +++ b/src/apps/debugger/files/SourceFile.cpp @@ -63,12 +63,16 @@ SourceFile::Init(const char* path) return errno; } - if (st.st_size > kMaxSourceFileSize) + if (st.st_size > kMaxSourceFileSize) { + close (fd); return B_FILE_TOO_LARGE; + } size_t fileSize = st.st_size; - if (fileSize == 0) + if (fileSize == 0) { + close (fd); return B_BAD_VALUE; + } // allocate the content buffer fFileContent = (char*)malloc(fileSize + 1);