Hi!

13-Мар-2004 12:40 [EMAIL PROTECTED] (Luchezar Georgiev) wrote to FreeDOS-kernel
<[EMAIL PROTECTED]>:

LG> symptom for all memory managers, even Tom's tiny but great in value
LG> TALLOC.C! These days, another colleague of mine found a bug in it causing
LG> the dreaded memory leakage when repeatedly freeing and allocating a block.
LG> The bug was in malloc() and the second patch below fixes it. I've uploaded
LG> +++ src/kernel/sys/talloc.c2004-03-12 15:54:14.000000000 +0200

     For SYS (and any other program, where heap isn't [active] used) I
develop much more compact and simpler edition:

______________O\_/_________________________________\_/O______________
/* Replace: malloc() and free().
   Description: simplified memory management over static buffer without
                releasing of allocated memory. MALLOC_BUF_SIZE defines
                size of static buffer (default value is 8k).
*/

#include <malloc.h>

#ifndef MALLOC_BUF_SIZE
# define MALLOC_BUF_SIZE (8u*1024u)
#endif

void *malloc (size_t sz) {
        static char malloc_buffer [MALLOC_BUF_SIZE];
        static size_t malloc_next = 0;

        size_t old = malloc_next;
        if (sizeof malloc_buffer - old < sz)
                return NULL;

        malloc_next += sz;
        return malloc_buffer + old;
}

#ifdef __WATCOMC__
void *_nmalloc (size_t sz) { return malloc (sz); }
void *realloc (void *p, size_t sz) { (void)p; (void)sz; return NULL; }
#endif

#ifdef __cplusplus
void free (void*) {}
#else
void free () {}
#endif
_____________________________________________________________________
              O/~\                                 /~\O

Place this into MALLOC.INC, and then use at the program end:

______________O\_/_________________________________\_/O______________
#ifdef __WATCOMC__
# include "malloc.inc"
#endif
_____________________________________________________________________
              O/~\                                 /~\O

This is excerpt from BOOTFIX - because it itself doesn't uses heap, and for
BC startup streams maked nonbuffered, so malloc() stub in BOOTFIX is need
only for OW.




-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Freedos-kernel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freedos-kernel

Reply via email to