From 246c199c405c382ff1260fc30c8ab48b992a2a5c Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Tue, 19 Mar 2013 01:34:22 +0100 Subject: [PATCH] nfs4: Fix memory leaks in case of error in ReplyInterpreter::_DecodeAttrs() This patch fixes CID 991505, 991504, 991502, 991500, 991499, 991496. --- .../kernel/file_systems/nfs4/ReplyInterpreter.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp b/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp index 644460edca..e13808cbff 100644 --- a/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp +++ b/src/add-ons/kernel/file_systems/nfs4/ReplyInterpreter.cpp @@ -11,6 +11,7 @@ #include +#include #include #include "Cookie.h" @@ -554,6 +555,7 @@ ReplyInterpreter::_DecodeAttrs(XDR::ReadStream& str, AttrValue** attrs, uint32* bitmap = new(std::nothrow) uint32[bcount]; if (bitmap == NULL) return B_NO_MEMORY; + ArrayDeleter _(bitmap); uint32 attr_count = 0; for (uint32 i = 0; i < bcount; i++) { @@ -573,10 +575,8 @@ ReplyInterpreter::_DecodeAttrs(XDR::ReadStream& str, AttrValue** attrs, XDR::ReadStream stream(const_cast(ptr), size); AttrValue* values = new(std::nothrow) AttrValue[attr_count]; - if (values == NULL) { - delete[] bitmap; + if (values == NULL) return B_NO_MEMORY; - } uint32 current = 0; @@ -774,11 +774,13 @@ ReplyInterpreter::_DecodeAttrs(XDR::ReadStream& str, AttrValue** attrs, current++; } - delete[] bitmap; - *count = attr_count; *attrs = values; - return str.IsEOF() ? B_BAD_VALUE : B_OK; + if (str.IsEOF()) { + delete[] values; + return B_BAD_VALUE; + } + return B_OK; }