- apply patch.memleaks-tominac from Darko Tominac <darko.tominac@zg.tel.hr>

which fixes some potential memory leaks
This commit is contained in:
Bryce Denney 2001-12-21 19:33:18 +00:00
parent 9884c923cd
commit cbd68598a3
8 changed files with 138 additions and 16 deletions

View File

@ -1,10 +1,10 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.cc,v 1.36 2001-12-12 10:38:39 cbothamy Exp $
// $Id: siminterface.cc,v 1.37 2001-12-21 19:33:18 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
/*
* gui/siminterface.cc
* $Id: siminterface.cc,v 1.36 2001-12-12 10:38:39 cbothamy Exp $
* $Id: siminterface.cc,v 1.37 2001-12-21 19:33:18 bdenney Exp $
*
* Defines the actual link between bx_simulator_interface_c methods
* and the simulator. This file includes bochs.h because it needs
@ -32,6 +32,7 @@ class bx_real_sim_c : public bx_simulator_interface_c {
int enabled;
public:
bx_real_sim_c ();
~bx_real_sim_c ();
virtual int get_init_done () { return init_done; }
virtual int set_init_done (int n) { init_done = n; return 0;}
virtual int register_param (bx_id id, bx_param_c *it);
@ -127,6 +128,15 @@ bx_real_sim_c::bx_real_sim_c ()
param_registry = new bx_param_c* [registry_alloc_size];
}
bx_real_sim_c::~bx_real_sim_c ()
{
if ( param_registry != NULL )
{
delete [] param_registry;
param_registry = NULL;
}
}
int
bx_real_sim_c::register_param (bx_id id, bx_param_c *it)
{
@ -449,6 +459,26 @@ bx_param_string_c::bx_param_string_c (bx_id id,
set (initial_val);
}
bx_param_string_c::~bx_param_string_c ()
{
if ( this->val != NULL )
{
delete [] this->val;
this->val = NULL;
}
if ( this->initial_val != NULL )
{
delete [] this->initial_val;
this->initial_val = NULL;
}
if ( this->options != NULL )
{
delete [] this->options;
this->options = NULL;
}
}
void
bx_param_string_c::reset () {
strncpy (this->val, this->initial_val, maxsize);
@ -516,6 +546,30 @@ bx_list_c::bx_list_c (bx_id id, char *name, char *description, bx_param_c **init
init ();
}
bx_list_c::~bx_list_c()
{
if (this->list)
{
delete [] this->list;
this->list = NULL;
}
if ( this->title != NULL)
{
delete this->title;
this->title = NULL;
}
if (this->options != NULL)
{
delete this->options;
this->options = NULL;
}
if ( this->choice != NULL )
{
delete this->choice;
this->choice = NULL;
}
}
void
bx_list_c::init ()
{

View File

@ -1,10 +1,10 @@
/////////////////////////////////////////////////////////////////////////
// $Id: siminterface.h,v 1.29 2001-12-14 17:54:58 cbothamy Exp $
// $Id: siminterface.h,v 1.30 2001-12-21 19:33:18 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
/*
* gui/siminterface.h
* $Id: siminterface.h,v 1.29 2001-12-14 17:54:58 cbothamy Exp $
* $Id: siminterface.h,v 1.30 2001-12-21 19:33:18 bdenney Exp $
*
* Interface to the simulator, currently only used by control.cc.
* The base class bx_simulator_interface_c, contains only virtual functions
@ -229,6 +229,7 @@ public:
char *description,
char *initial_val,
int maxsize=-1);
~bx_param_string_c ();
void reset ();
void set_handler (param_string_event_handler handler);
Bit32s get (char *buf, int len);
@ -274,6 +275,7 @@ public:
} bx_listopt_bits;
//bx_list_c (bx_id id, int maxsize);
bx_list_c (bx_id id, char *name, char *description, bx_param_c **init_list);
~bx_list_c();
void add (bx_param_c *param);
bx_param_c *get (int index);
bx_param_num_c *get_options () { return options; }

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: win32.cc,v 1.21 2001-12-13 18:36:29 vruppert Exp $
// $Id: win32.cc,v 1.22 2001-12-21 19:33:18 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -855,7 +855,8 @@ unsigned bx_gui_c::create_bitmap(const unsigned char *bmap, unsigned xdim,
for (unsigned i=0; i<ydim * xdim/8; i++)
data[i] = reverse_bitorder(bmap[i]);
SetBitmapBits(bx_bitmaps[bx_bitmap_entries].bmap, ydim * xdim/8, data);
free(data);
delete [] data;
data = NULL;
bx_bitmaps[bx_bitmap_entries].xdim = xdim;
bx_bitmaps[bx_bitmap_entries].ydim = ydim;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: harddrv.cc,v 1.41 2001-11-12 03:34:45 bdenney Exp $
// $Id: harddrv.cc,v 1.42 2001-12-21 19:33:18 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -85,6 +85,8 @@ static unsigned curr_multiple_sectors = 0; // was 0x3f
bx_hard_drive_c::bx_hard_drive_c(void)
{
s[0].hard_drive = NULL;
s[1].hard_drive = NULL;
put("HD");
settype(HDLOG);
#if EXTERNAL_DISK_SIMULATOR
@ -106,17 +108,27 @@ bx_hard_drive_c::bx_hard_drive_c(void)
bx_hard_drive_c::~bx_hard_drive_c(void)
{
// nothing for now
BX_DEBUG(("Exit."));
if ( s[0].hard_drive != NULL ) /* DT 17.12.2001 21:55 */
{
delete s[0].hard_drive;
s[0].hard_drive = NULL;
}
if ( s[1].hard_drive != NULL )
{
delete s[1].hard_drive;
s[1].hard_drive = NULL; /* DT 17.12.2001 21:56 */
}
}
void
bx_hard_drive_c::init(bx_devices_c *d, bx_cmos_c *cmos)
{
BX_HD_THIS devices = d;
BX_DEBUG(("Init $Id: harddrv.cc,v 1.41 2001-11-12 03:34:45 bdenney Exp $"));
BX_DEBUG(("Init $Id: harddrv.cc,v 1.42 2001-12-21 19:33:18 bdenney Exp $"));
/* HARD DRIVE 0 */

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: unmapped.cc,v 1.13 2001-10-03 13:10:38 bdenney Exp $
// $Id: unmapped.cc,v 1.14 2001-12-21 19:33:18 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -52,7 +52,11 @@ bx_unmapped_c::bx_unmapped_c(void)
bx_unmapped_c::~bx_unmapped_c(void)
{
// nothing for now
if ( bioslog != NULL ) /* DT 17.12.2001 21:32 */
{
delete bioslog;
bioslog = NULL;
}
}
void

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: logio.cc,v 1.14 2001-12-08 18:08:24 bdenney Exp $
// $Id: logio.cc,v 1.15 2001-12-21 19:33:18 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -195,9 +195,10 @@ iofunctions::~iofunctions(void)
logfunctions::logfunctions(void)
{
prefix = NULL;
put(" ");
settype(GENLOG);
if(io == NULL && Allocio == 0) {
if (io == NULL && Allocio == 0) {
Allocio = 1;
io = new iofunc_t(stderr);
}
@ -210,6 +211,7 @@ logfunctions::logfunctions(void)
logfunctions::logfunctions(iofunc_t *iofunc)
{
prefix = NULL;
put(" ");
settype(GENLOG);
setio(iofunc);
@ -221,6 +223,16 @@ logfunctions::logfunctions(iofunc_t *iofunc)
logfunctions::~logfunctions(void)
{
if (io != NULL)
{
delete io;
io = NULL;
}
if ( this->prefix )
{
free(this->prefix);
this->prefix = NULL;
}
}
void
@ -238,6 +250,16 @@ logfunctions::put(char *p)
char *tmpbuf;
tmpbuf=strdup("[ ]");// if we ever have more than 32 chars,
// we need to rethink this
if ( tmpbuf == NULL)
{
return ; /* allocation not successful */
}
if ( this->prefix != NULL )
{
free(this->prefix); /* free previously allocated memory */
this->prefix = NULL;
}
int len=strlen(p);
for(int i=1;i<len+1;i++) {
tmpbuf[i]=p[i-1];

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: main.cc,v 1.81 2001-12-14 17:55:51 cbothamy Exp $
// $Id: main.cc,v 1.82 2001-12-21 19:33:18 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -1195,13 +1195,15 @@ parse_bochsrc(char *rcfile)
static void
parse_line_unformatted(char *context, char *line)
{
#define MAX_PARAMS_LEN 40
char *ptr;
unsigned i, string_i;
char string[512];
char *params[40];
char *params[MAX_PARAMS_LEN];
int num_params;
Boolean inquotes = 0;
memset(params, 0, sizeof(params));
if (line == NULL) return;
// if passed nothing but whitespace, just return
@ -1247,10 +1249,30 @@ parse_line_unformatted(char *context, char *line)
}
}
string[string_i] = '\0';
if ( params[num_params] != NULL )
{
free(params[num_params]);
params[num_params] = NULL;
}
if ( num_params < MAX_PARAMS_LEN )
{
params[num_params++] = strdup (string);
ptr = strtok(NULL, ",");
}
else
{
BX_PANIC (("too many parameters, max is %d\n", MAX_PARAMS_LEN));
}
}
parse_line_formatted(context, num_params, &params[0]);
for (i=0; i < MAX_PARAMS_LEN; i++)
{
if ( params[i] != NULL )
{
free(params[i]);
params[i] = NULL;
}
}
}
static void

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: state_file.cc,v 1.8 2001-10-03 13:10:37 bdenney Exp $
// $Id: state_file.cc,v 1.9 2001-12-21 19:33:18 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -128,4 +128,9 @@ state_file::state_file (FILE *f)
state_file::~state_file()
{
BX_DEBUG(("Exit."));
if ( log != NULL )
{
delete log;
log = NULL;
}
}