nfs4: Fix memory leaks in case of errors while reading a directory
This fixes CID 991497.
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
#include "IdMap.h"
|
#include "IdMap.h"
|
||||||
#include "Inode.h"
|
#include "Inode.h"
|
||||||
#include "NFS4Inode.h"
|
#include "NFS4Inode.h"
|
||||||
@@ -989,12 +991,14 @@ NFS4Inode::ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
|
|||||||
if (result != B_OK)
|
if (result != B_OK)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
ArrayDeleter<AttrValue> beforeDeleter(before);
|
||||||
|
|
||||||
result = reply.ReadDir(dirCookie, dirCookieVerf, dirents, count, eof);
|
result = reply.ReadDir(dirCookie, dirCookieVerf, dirents, count, eof);
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
delete[] before;
|
delete[] before;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
ArrayDeleter<DirEntry> entriesDeleter(*dirents);
|
||||||
|
|
||||||
AttrValue* after;
|
AttrValue* after;
|
||||||
result = reply.GetAttr(&after, &attrCount);
|
result = reply.GetAttr(&after, &attrCount);
|
||||||
@@ -1002,6 +1006,7 @@ NFS4Inode::ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
|
|||||||
delete[] before;
|
delete[] before;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
ArrayDeleter<AttrValue> afterDeleter(after);
|
||||||
|
|
||||||
if ((*change == 0
|
if ((*change == 0
|
||||||
&& before[0].fData.fValue64 == after[0].fData.fValue64)
|
&& before[0].fData.fValue64 == after[0].fData.fValue64)
|
||||||
@@ -1010,9 +1015,7 @@ NFS4Inode::ReadDirOnce(DirEntry** dirents, uint32* count, OpenDirCookie* cookie,
|
|||||||
else
|
else
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
delete[] before;
|
entriesDeleter.Detach();
|
||||||
delete[] after;
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
} while (true);
|
} while (true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -427,7 +427,12 @@ ReplyInterpreter::ReadDir(uint64* cookie, uint64* cookieVerf,
|
|||||||
*_count = count;
|
*_count = count;
|
||||||
*dirents = entries;
|
*dirents = entries;
|
||||||
|
|
||||||
return fReply->Stream().IsEOF() ? B_BAD_VALUE : B_OK;
|
if (fReply->Stream().IsEOF()) {
|
||||||
|
delete[] entries;
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user