* Fixed serious memory leak in team_create_thread_start(). The

destructor of the automatic KPath variable was never invoked, since
  normally arch_thread_enter_userspace() would not return and thus the
  function scope never be left. After a standard "jam @image" almost
  42 MB of kernel heap were lost this way.
* Added a few warning comments in functions that shouldn't use automatic
  variables with a destructor in the function scope either.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26336 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-07-09 03:58:38 +00:00
parent d1d7044ed1
commit 74d5c1e499
+9
View File
@@ -1041,6 +1041,9 @@ team_create_thread_start(void *args)
// the arguments are already on the user stack, we no longer need // the arguments are already on the user stack, we no longer need
// them in this form // them in this form
// NOTE: Normally arch_thread_enter_userspace() never returns, that is
// automatic variables with function scope will never be destroyed.
{
// find runtime_loader path // find runtime_loader path
KPath runtimeLoaderPath; KPath runtimeLoaderPath;
err = find_directory(B_BEOS_SYSTEM_DIRECTORY, gBootDevice, false, err = find_directory(B_BEOS_SYSTEM_DIRECTORY, gBootDevice, false,
@@ -1055,6 +1058,8 @@ team_create_thread_start(void *args)
if (err == B_OK) if (err == B_OK)
err = elf_load_user_image(runtimeLoaderPath.Path(), team, 0, &entry); err = elf_load_user_image(runtimeLoaderPath.Path(), team, 0, &entry);
}
if (err < B_OK) { if (err < B_OK) {
// Luckily, we don't have to clean up the mess we created - that's // Luckily, we don't have to clean up the mess we created - that's
// done for us by the normal team deletion process // done for us by the normal team deletion process
@@ -1247,6 +1252,8 @@ static status_t
exec_team(const char *path, char**& _flatArgs, size_t flatArgsSize, exec_team(const char *path, char**& _flatArgs, size_t flatArgsSize,
int32 argCount, int32 envCount) int32 argCount, int32 envCount)
{ {
// NOTE: Since this function normally doesn't return, don't use automatic
// variables that need destruction in the function scope.
char** flatArgs = _flatArgs; char** flatArgs = _flatArgs;
struct team *team = thread_get_current_thread()->team; struct team *team = thread_get_current_thread()->team;
struct team_arg *teamArgs; struct team_arg *teamArgs;
@@ -2949,6 +2956,8 @@ status_t
_user_exec(const char *userPath, const char* const* userFlatArgs, _user_exec(const char *userPath, const char* const* userFlatArgs,
size_t flatArgsSize, int32 argCount, int32 envCount) size_t flatArgsSize, int32 argCount, int32 envCount)
{ {
// NOTE: Since this function normally doesn't return, don't use automatic
// variables that need destruction in the function scope.
char path[B_PATH_NAME_LENGTH]; char path[B_PATH_NAME_LENGTH];
if (!IS_USER_ADDRESS(userPath) || !IS_USER_ADDRESS(userFlatArgs) if (!IS_USER_ADDRESS(userPath) || !IS_USER_ADDRESS(userFlatArgs)