fix some memory leaks (part of bug #140

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16322 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2006-02-10 10:13:43 +00:00
parent 0dd48593ea
commit 718a665ba9
2 changed files with 17 additions and 2 deletions

View File

@ -14,6 +14,7 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include "Keymap.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ByteOrder.h>
@ -80,8 +81,17 @@ Keymap::Keymap() :
key_map *keys;
get_key_map(&keys, &fChars);
if (keys)
if (keys) {
memcpy(&fKeys, keys, sizeof(key_map));
free(keys);
}
}
Keymap::~Keymap()
{
if (fChars)
free(fChars);
}
@ -364,12 +374,16 @@ status_t
Keymap::LoadCurrent()
{
key_map *keys = NULL;
if (fChars)
free(fChars);
fChars = NULL;
get_key_map(&keys, &fChars);
if (!keys) {
fprintf(stderr, "error while getting current keymap!\n");
return B_ERROR;
}
memcpy(&fKeys, keys, sizeof(fKeys));
delete keys;
free(keys);
return B_OK;
}

View File

@ -23,6 +23,7 @@ class Keymap
{
public:
Keymap();
~Keymap();
void DumpKeymap();
bool IsModifierKey(uint32 keyCode);
uint32 Modifier(uint32 keyCode);