[haiku-commits] r40037 - haiku/trunk/src/apps/debugger/files

  • From: revol@xxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 29 Dec 2010 21:05:24 +0100 (CET)

Author: mmu_man
Date: 2010-12-29 21:05:24 +0100 (Wed, 29 Dec 2010)
New Revision: 40037
Changeset: http://dev.haiku-os.org/changeset/40037

Modified:
   haiku/trunk/src/apps/debugger/files/SourceFile.cpp
Log:
Avoid leaking a file descriptor on error. Thanks PovAddict for running cppcheck.


Modified: haiku/trunk/src/apps/debugger/files/SourceFile.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/files/SourceFile.cpp  2010-12-29 20:04:58 UTC 
(rev 40036)
+++ haiku/trunk/src/apps/debugger/files/SourceFile.cpp  2010-12-29 20:05:24 UTC 
(rev 40037)
@@ -63,12 +63,16 @@
                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);


Other related posts: