From f86cfd4088fb0a6d535201e8da9372c1d8257b19 Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Thu, 2 Nov 2006 18:12:43 +0900 Subject: [PATCH] msi: Avoid a memory leak by freeing actions scripts in one place only. --- dlls/msi/action.c | 6 +----- dlls/msi/helpers.c | 19 ++++++++++++------- dlls/msi/msipriv.h | 1 + 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dlls/msi/action.c b/dlls/msi/action.c index a6cb5c208a4..8e7641398d9 100644 --- a/dlls/msi/action.c +++ b/dlls/msi/action.c @@ -1491,14 +1491,10 @@ static UINT execute_script(MSIPACKAGE *package, UINT script ) ui_actionstart(package, action); TRACE("Executing Action (%s)\n",debugstr_w(action)); rc = ACTION_PerformAction(package, action, TRUE); - msi_free(package->script->Actions[script][i]); if (rc != ERROR_SUCCESS) break; } - msi_free(package->script->Actions[script]); - - package->script->ActionCount[script] = 0; - package->script->Actions[script] = NULL; + msi_free_action_script(package, script); return rc; } diff --git a/dlls/msi/helpers.c b/dlls/msi/helpers.c index 83a9f30214f..acb0f77a8c5 100644 --- a/dlls/msi/helpers.c +++ b/dlls/msi/helpers.c @@ -384,6 +384,17 @@ UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action) return ERROR_SUCCESS; } +void msi_free_action_script(MSIPACKAGE *package, UINT script) +{ + int i; + for (i = 0; i < package->script->ActionCount[script]; i++) + msi_free(package->script->Actions[script][i]); + + msi_free(package->script->Actions[script]); + package->script->Actions[script] = NULL; + package->script->ActionCount[script] = 0; +} + static void remove_tracked_tempfiles(MSIPACKAGE* package) { struct list *item, *cursor; @@ -571,13 +582,7 @@ void ACTION_free_package_structures( MSIPACKAGE* package) if (package->script) { for (i = 0; i < TOTAL_SCRIPTS; i++) - { - int j; - for (j = 0; j < package->script->ActionCount[i]; j++) - msi_free(package->script->Actions[i][j]); - - msi_free(package->script->Actions[i]); - } + msi_free_action_script(package, i); for (i = 0; i < package->script->UniqueActionsCount; i++) msi_free(package->script->UniqueActions[i]); diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index fa0c2251692..2e4f5d2b491 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -752,6 +752,7 @@ extern MSIFILE *get_loaded_file( MSIPACKAGE* package, LPCWSTR file ); extern MSIFOLDER *get_loaded_folder( MSIPACKAGE *package, LPCWSTR dir ); extern int track_tempfile(MSIPACKAGE *package, LPCWSTR name, LPCWSTR path); extern UINT schedule_action(MSIPACKAGE *package, UINT script, LPCWSTR action); +extern void msi_free_action_script(MSIPACKAGE *package, UINT script); extern LPWSTR build_icon_path(MSIPACKAGE *, LPCWSTR); extern LPWSTR build_directory_name(DWORD , ...); extern BOOL create_full_pathW(const WCHAR *path);