From 10517bd1fcf73d5f333afa769b77d8dd2f2d441d Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Thu, 28 Feb 2002 15:36:00 +0000 Subject: [PATCH] * mad.c: Make mem_areas dynamically growing. (mad_init): Allocate memory for mem_areas. (mad_alloc): Grow mem_areas if it is exhausted. --- src/ChangeLog | 4 ++++ src/mad.c | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 3cad58db4..bac970db2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2002-02-28 Andrew V. Samoilov + * mad.c: Make mem_areas dynamically growing. + (mad_init): Allocate memory for mem_areas. + (mad_alloc): Grow mem_areas if it is exhausted. + * filegui.c (file_mask_dialog): Enable 'follow Links' and 'preserve Attributes' features in Move dialog. (file_bps_show): Translate messages. diff --git a/src/mad.c b/src/mad.c index 64f41fe7f..07bda38d1 100644 --- a/src/mad.c +++ b/src/mad.c @@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include + +#ifdef HAVE_MAD #include "mad.h" #undef tempnam @@ -47,12 +49,9 @@ #endif #include -/* Here to avoid non empty translation units */ -#ifdef HAVE_MAD - -/* Maximum number of memory area handles, - increase this if you run out of handles */ -#define MAD_MAX_AREAS 20000 /* vfs leaks Lots of memory*/ +/* Number of memory area handles currently allocated */ +#define MAD_AREAS_STEP 10000 +static int MAD_MAX_AREAS = MAD_AREAS_STEP; /* Maximum file name length */ #define MAD_MAX_FILE 50 /* Signature for detecting overwrites */ @@ -67,7 +66,7 @@ typedef struct { long *end_sig; } mad_mem_area; -static mad_mem_area mem_areas [MAD_MAX_AREAS]; +static mad_mem_area *mem_areas; static FILE *memlog; #define MAD_CHECK_CALL_FACTOR 30 /* Perform actual test every N call. */ @@ -84,6 +83,8 @@ void mad_init (void) { memlog = stderr; +/* Here to prevent crash if mad_free or mad_realloc called before mad_alloc */ + mem_areas = g_new0 (mad_mem_area, MAD_MAX_AREAS); } void mad_set_debug (const char *file) @@ -154,9 +155,13 @@ void *mad_alloc (int size, const char *file, int line) if (! mem_areas [i].in_use) break; } - if (i >= MAD_MAX_AREAS) - mad_fatal_error("Out of memory area handles. Increase the value of MAD_MAX_AREAS.", NULL, file, line); - + if (i >= MAD_MAX_AREAS) { + MAD_MAX_AREAS += MAD_AREAS_STEP; + mem_areas = g_realloc (mem_areas, MAD_MAX_AREAS * sizeof (mad_mem_area)); + if (mem_areas == NULL) + mad_fatal_error ("Out of memory area handles.", NULL, file, line); + memset (mem_areas + i, 0, MAD_AREAS_STEP * sizeof (mad_mem_area)); + } Alloc_idx_hint = i+1; if (i > Stats.last_max_i) Stats.last_max_i = i;