Fixed some memory leaks, fChars was never freed.
Now uses (nothrow) for fChars and checks if the allocation succeeded. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14947 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -295,16 +295,19 @@ InputServer::LoadKeymap()
|
|||||||
if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys))
|
if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
for (uint32 i=0; i<sizeof(fKeys)/4; i++)
|
for (uint32 i = 0; i < sizeof(fKeys)/4; i++)
|
||||||
((uint32*)&fKeys)[i] = B_BENDIAN_TO_HOST_INT32(((uint32*)&fKeys)[i]);
|
((uint32*)&fKeys)[i] = B_BENDIAN_TO_HOST_INT32(((uint32*)&fKeys)[i]);
|
||||||
|
|
||||||
if (file.Read(&fCharsSize, sizeof(uint32)) < (ssize_t)sizeof(uint32))
|
if (file.Read(&fCharsSize, sizeof(uint32)) < (ssize_t)sizeof(uint32))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
fCharsSize = B_BENDIAN_TO_HOST_INT32(fCharsSize);
|
fCharsSize = B_BENDIAN_TO_HOST_INT32(fCharsSize);
|
||||||
if (!fChars)
|
|
||||||
delete[] fChars;
|
delete[] fChars;
|
||||||
fChars = new char[fCharsSize];
|
fChars = new (nothrow) char[fCharsSize];
|
||||||
|
if (fChars == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
if (file.Read(fChars, fCharsSize) != (signed)fCharsSize)
|
if (file.Read(fChars, fCharsSize) != (signed)fCharsSize)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
@@ -315,11 +318,13 @@ InputServer::LoadKeymap()
|
|||||||
status_t
|
status_t
|
||||||
InputServer::LoadSystemKeymap()
|
InputServer::LoadSystemKeymap()
|
||||||
{
|
{
|
||||||
if (!fChars)
|
delete[] fChars;
|
||||||
delete[] fChars;
|
|
||||||
fKeys = sSystemKeymap;
|
fKeys = sSystemKeymap;
|
||||||
fCharsSize = sSystemKeyCharsSize;
|
fCharsSize = sSystemKeyCharsSize;
|
||||||
fChars = new char[fCharsSize];
|
fChars = new (nothrow) char[fCharsSize];
|
||||||
|
if (fChars == NULL)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
memcpy(fChars, sSystemKeyChars, fCharsSize);
|
memcpy(fChars, sSystemKeyChars, fCharsSize);
|
||||||
|
|
||||||
// we save this keymap to file
|
// we save this keymap to file
|
||||||
|
|||||||
Reference in New Issue
Block a user