Commit 31ab84f2 authored by Richard Manby's avatar Richard Manby
Browse files

Fixed an RMA leak.

If a module written in C uses function getenv, buffer space
is allocated in the RMA. This buffer was never freed, leading
to RMA leakage when the module was 'RMKill'ed or 'RMReInit'ed.

Changes

 c.armsys
   added function _terminate_getenv to free the buffer

 c.stdlib
   added flag getenv_finalised to the exit_s structure

   initialised getenv_finalised in function _exit_init

   atexit tests getenv_finalised, calls _terminate_getenv

 s.version
   version string changed to 4.86 (27 Jul 1998)
parent 87d574b0
...@@ -370,6 +370,14 @@ char *getenv(const char *name) ...@@ -370,6 +370,14 @@ char *getenv(const char *name)
return _getenv_value; return _getenv_value;
} }
void _terminate_getenv(void)
{
if (_getenv_value)
free(_getenv_value);
_getenv_value = NULL;
}
#ifdef DDE #ifdef DDE
#define DDEUtils_SetCLSize 0x42581 #define DDEUtils_SetCLSize 0x42581
#define DDEUtils_SetCL 0x42582 #define DDEUtils_SetCL 0x42582
......
...@@ -103,7 +103,7 @@ static union { vprocp p; int i; } _exitvector[EXIT_LIMIT] = {}; ...@@ -103,7 +103,7 @@ static union { vprocp p; int i; } _exitvector[EXIT_LIMIT] = {};
/* initialised so not in bss (or shared library trouble) */ /* initialised so not in bss (or shared library trouble) */
static struct { static struct {
char number_of_exit_functions; char number_of_exit_functions;
char alloc_finalised, io_finalised; char alloc_finalised, io_finalised, getenv_finalised;
} exit_s; } exit_s;
void _exit_init() void _exit_init()
...@@ -117,7 +117,7 @@ void _exit_init() ...@@ -117,7 +117,7 @@ void _exit_init()
} }
} else } else
exit_s.number_of_exit_functions = 0; exit_s.number_of_exit_functions = 0;
exit_s.alloc_finalised = 0; exit_s.io_finalised = 0; exit_s.alloc_finalised = 0; exit_s.io_finalised = 0; exit_s.getenv_finalised = 0;
} }
int atexit(vprocp func) int atexit(vprocp func)
...@@ -137,6 +137,7 @@ void _lib_shutdown() ...@@ -137,6 +137,7 @@ void _lib_shutdown()
_call_client_0(fn); _call_client_0(fn);
} }
/* ensure no recursion if finalisation fails */ /* ensure no recursion if finalisation fails */
if (!exit_s.getenv_finalised) { exit_s.getenv_finalised = 1; _terminate_getenv(); }
if (!exit_s.alloc_finalised) { exit_s.alloc_finalised = 1; _terminate_user_alloc(); } if (!exit_s.alloc_finalised) { exit_s.alloc_finalised = 1; _terminate_user_alloc(); }
if (!exit_s.io_finalised) { exit_s.io_finalised = 1; _terminateio(); } if (!exit_s.io_finalised) { exit_s.io_finalised = 1; _terminateio(); }
} }
......
...@@ -12,5 +12,5 @@ ...@@ -12,5 +12,5 @@
; See the License for the specific language governing permissions and ; See the License for the specific language governing permissions and
; limitations under the License. ; limitations under the License.
; ;
DCB "4.85 (19 Dec 1996)" DCB "4.86 (27 Jul 1998)"
END END
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment