From 33a1ae7cb4c0b1fddcb709803255bda1d079afd0 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Wed, 6 Aug 2008 14:09:39 -0700 Subject: [PATCH] Use helper function to remove duplicate code --- dlls/cabinet/fdi.c | 90 ++++++++++++++++++++-------------------------------- 1 files changed, 35 insertions(+), 55 deletions(-) diff --git a/dlls/cabinet/fdi.c b/dlls/cabinet/fdi.c index 283295d..0c9b18c 100644 --- a/dlls/cabinet/fdi.c +++ b/dlls/cabinet/fdi.c @@ -2277,6 +2277,39 @@ static void free_decompression_temps(HFD } } +static void free_decompression_mem(HFDI hfdi, struct fdi_folder *fol, + fdi_decomp_state *decomp_state, fdi_decomp_state *sentinel_decomp_state, + struct fdi_file *file) +{ + while (decomp_state) { + fdi_decomp_state *prev_fds; + + PFDI_CLOSE(hfdi, CAB(cabhf)); + + /* free the storage remembered by mii */ + if (CAB(mii).nextname) PFDI_FREE(hfdi, CAB(mii).nextname); + if (CAB(mii).nextinfo) PFDI_FREE(hfdi, CAB(mii).nextinfo); + if (CAB(mii).prevname) PFDI_FREE(hfdi, CAB(mii).prevname); + if (CAB(mii).previnfo) PFDI_FREE(hfdi, CAB(mii).previnfo); + + while (CAB(firstfol)) { + fol = CAB(firstfol); + CAB(firstfol) = CAB(firstfol)->next; + PFDI_FREE(hfdi, fol); + } + while (CAB(firstfile)) { + file = CAB(firstfile); + if (file->filename) PFDI_FREE(hfdi, (void *)file->filename); + CAB(firstfile) = CAB(firstfile)->next; + PFDI_FREE(hfdi, file); + } + prev_fds = decomp_state; + decomp_state = CAB(next); + if (prev_fds != sentinel_decomp_state) + PFDI_FREE(hfdi, prev_fds); + } +} + /*********************************************************************** * FDICopy (CABINET.22) * @@ -2874,34 +2907,7 @@ BOOL __cdecl FDICopy( } free_decompression_temps(hfdi, fol, decomp_state); - - while (decomp_state) { - fdi_decomp_state *prev_fds; - - PFDI_CLOSE(hfdi, CAB(cabhf)); - - /* free the storage remembered by mii */ - if (CAB(mii).nextname) PFDI_FREE(hfdi, CAB(mii).nextname); - if (CAB(mii).nextinfo) PFDI_FREE(hfdi, CAB(mii).nextinfo); - if (CAB(mii).prevname) PFDI_FREE(hfdi, CAB(mii).prevname); - if (CAB(mii).previnfo) PFDI_FREE(hfdi, CAB(mii).previnfo); - - while (CAB(firstfol)) { - fol = CAB(firstfol); - CAB(firstfol) = CAB(firstfol)->next; - PFDI_FREE(hfdi, fol); - } - while (CAB(firstfile)) { - file = CAB(firstfile); - if (file->filename) PFDI_FREE(hfdi, (void *)file->filename); - CAB(firstfile) = CAB(firstfile)->next; - PFDI_FREE(hfdi, file); - } - prev_fds = decomp_state; - decomp_state = CAB(next); - if (prev_fds != &_decomp_state) - PFDI_FREE(hfdi, prev_fds); - } + free_decompression_mem(hfdi, fol, decomp_state, &_decomp_state, file); return TRUE; @@ -2911,33 +2917,7 @@ BOOL __cdecl FDICopy( if (filehf) PFDI_CLOSE(hfdi, filehf); - while (decomp_state) { - fdi_decomp_state *prev_fds; - - PFDI_CLOSE(hfdi, CAB(cabhf)); - - /* free the storage remembered by mii */ - if (CAB(mii).nextname) PFDI_FREE(hfdi, CAB(mii).nextname); - if (CAB(mii).nextinfo) PFDI_FREE(hfdi, CAB(mii).nextinfo); - if (CAB(mii).prevname) PFDI_FREE(hfdi, CAB(mii).prevname); - if (CAB(mii).previnfo) PFDI_FREE(hfdi, CAB(mii).previnfo); - - while (CAB(firstfol)) { - fol = CAB(firstfol); - CAB(firstfol) = CAB(firstfol)->next; - PFDI_FREE(hfdi, fol); - } - while (CAB(firstfile)) { - file = CAB(firstfile); - if (file->filename) PFDI_FREE(hfdi, (void *)file->filename); - CAB(firstfile) = CAB(firstfile)->next; - PFDI_FREE(hfdi, file); - } - prev_fds = decomp_state; - decomp_state = CAB(next); - if (prev_fds != &_decomp_state) - PFDI_FREE(hfdi, prev_fds); - } + free_decompression_mem(hfdi, fol, decomp_state, &_decomp_state, file); return FALSE; } -- 1.4.1