nfs4: Fix memory leaks in case of errors while reading a directory

This fixes CID 991497.
This commit is contained in:
Pawel Dziepak
2013-03-19 02:52:39 +01:00
parent 83b13040c8
commit b302859608
2 changed files with 12 additions and 4 deletions
@@ -7,6 +7,8 @@
*/
#include <AutoDeleter.h>
#include "IdMap.h"
#include "Inode.h"
#include "NFS4Inode.h"
@@ -989,12 +991,14 @@ NFS4Inode::ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
if (result != B_OK)
return result;
}
ArrayDeleter<AttrValue> beforeDeleter(before);
result = reply.ReadDir(dirCookie, dirCookieVerf, dirents, count, eof);
if (result != B_OK) {
delete[] before;
return result;
}
ArrayDeleter<DirEntry> entriesDeleter(*dirents);
AttrValue* after;
result = reply.GetAttr(&after, &attrCount);
@@ -1002,6 +1006,7 @@ NFS4Inode::ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
delete[] before;
return result;
}
ArrayDeleter<AttrValue> afterDeleter(after);
if ((*change == 0
&& before[0].fData.fValue64 == after[0].fData.fValue64)
@@ -1010,9 +1015,7 @@ NFS4Inode::ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
else
return B_ERROR;
delete[] before;
delete[] after;
entriesDeleter.Detach();
return B_OK;
} while (true);
}
@@ -427,7 +427,12 @@ ReplyInterpreter::ReadDir(uint64* cookie, uint64* cookieVerf,
*_count = count;
*dirents = entries;
return fReply->Stream().IsEOF() ? B_BAD_VALUE : B_OK;
if (fReply->Stream().IsEOF()) {
delete[] entries;
return B_BAD_VALUE;
}
return B_OK;
}