nfs4: Minor improvements to memory deallocation in few places
This commit is contained in:
@@ -411,6 +411,7 @@ ConnectionStream::Receive(void** _buffer, uint32* _size)
|
||||
return B_NO_MEMORY;
|
||||
} else
|
||||
buffer = ptr;
|
||||
MemoryDeleter bufferDeleter(buffer);
|
||||
|
||||
received = 0;
|
||||
do {
|
||||
@@ -418,15 +419,12 @@ ConnectionStream::Receive(void** _buffer, uint32* _size)
|
||||
record_size - received, 0);
|
||||
received += result;
|
||||
} while (result > 0 && received < record_size);
|
||||
if (result < 0) {
|
||||
result = errno;
|
||||
free(buffer);
|
||||
return result;
|
||||
} else if (result == 0) {
|
||||
free(buffer);
|
||||
if (result < 0)
|
||||
return errno;
|
||||
else if (result == 0)
|
||||
return ECONNABORTED;
|
||||
}
|
||||
|
||||
bufferDeleter.Detach();
|
||||
size += record_size;
|
||||
} while (!last_one);
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ FileInfo::CreateName(const char* dirPath, const char* name)
|
||||
if (fName == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
free(const_cast<char*>(fPath));
|
||||
fPath = NULL;
|
||||
if (dirPath != NULL) {
|
||||
char* path = reinterpret_cast<char*>(malloc(strlen(name) + 2
|
||||
+ strlen(dirPath)));
|
||||
@@ -68,12 +70,9 @@ FileInfo::CreateName(const char* dirPath, const char* name)
|
||||
strcat(path, "/");
|
||||
strcat(path, name);
|
||||
|
||||
free(const_cast<char*>(fPath));
|
||||
fPath = path;
|
||||
} else {
|
||||
free(const_cast<char*>(fPath));
|
||||
} else
|
||||
fPath = strdup(name);
|
||||
}
|
||||
|
||||
if (fPath == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "IdMap.h"
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <team.h>
|
||||
#include <util/AutoLock.h>
|
||||
@@ -122,21 +123,19 @@ IdMap::_GetBuffer(T value, int32 code)
|
||||
void* buffer = malloc(size);
|
||||
if (buffer == NULL)
|
||||
return NULL;
|
||||
MemoryDeleter bufferDeleter(buffer);
|
||||
|
||||
size = read_port(fReplyPort, &code, buffer, size);
|
||||
if (size < B_OK) {
|
||||
free(buffer);
|
||||
|
||||
if (_Repair() != B_OK)
|
||||
return 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code != MsgReply) {
|
||||
free(buffer);
|
||||
if (code != MsgReply)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bufferDeleter.Detach();
|
||||
return buffer;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user