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