From 9eb5b4659d24fcceaa4761c3dfa2c7b1d5e60e81 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 14 Apr 2010 01:02:05 +0200 Subject: win32: ash: sticky_free() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy --- shell/ash.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index 767c095e7..d21922f66 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -112,6 +112,8 @@ struct forkshell { struct strlist *strlist; pid_t pid; }; +static void sticky_free(void *p); +#define free(p) sticky_free(p) static int spawn_forkshell(struct job *jp, struct forkshell *fs, int mode); #endif @@ -13783,6 +13785,7 @@ forkshell_prepare(struct forkshell *fs) #undef exception_handler #undef trap #undef trap_ptr +static void *sticky_mem_start, *sticky_mem_end; static void forkshell_init(const char *idstr) { @@ -13801,6 +13804,9 @@ forkshell_init(const char *idstr) if (!fs) bb_error_msg_and_die("Invalid forkshell memory"); + /* this memory can't be freed */ + sticky_mem_start = fs; + sticky_mem_end = (char *) fs + fs->size; /* pointer fixup */ nodeptr = (int*)((char*)fs + fs->nodeptr_offset); while (*nodeptr) { @@ -13837,6 +13843,15 @@ forkshell_init(const char *idstr) fs->fp(fs); } +#undef free +static void +sticky_free(void *base) +{ + if (base >= sticky_mem_start && base < sticky_mem_end) + return; + free(base); +} + /*- * Copyright (c) 1989, 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. -- cgit v1.2.3-55-g6feb