From 19cda406126b0012a5cd9509ada41795846732ef Mon Sep 17 00:00:00 2001 From: "graham.gower" Date: Sun, 15 Nov 2009 08:59:19 +0000 Subject: [PATCH] Cleanup gz_close(). - Don't try to free() memory in a different process! - Move the function to a more appropriate file. - Fix error messages while here. git-svn-id: http://opkg.googlecode.com/svn/trunk@305 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- libbb/gz_open.c | 18 +++++++++++++----- libbb/unzip.c | 16 ---------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/libbb/gz_open.c b/libbb/gz_open.c index dbaf3bb..0ed1417 100644 --- a/libbb/gz_open.c +++ b/libbb/gz_open.c @@ -34,11 +34,11 @@ extern FILE *gz_open(FILE *compressed_file, int *pid) int unzip_pipe[2]; if (pipe(unzip_pipe)!=0) { - error_msg("pipe error"); + perror_msg("%s: pipe: ", __FUNCTION__); return(NULL); } if ((*pid = fork()) == -1) { - error_msg("fork failed"); + perror_msg("%s: fork: ", __FUNCTION__); return(NULL); } if (*pid==0) { @@ -51,8 +51,16 @@ extern FILE *gz_open(FILE *compressed_file, int *pid) exit(EXIT_SUCCESS); } close(unzip_pipe[1]); - if (unzip_pipe[0] == -1) { - error_msg("gzip stream init failed"); - } return(fdopen(unzip_pipe[0], "r")); } + +extern void gz_close(int gunzip_pid) +{ + if (kill(gunzip_pid, SIGTERM) == -1) { + perror_msg_and_die("%s: kill(gunzip_pid): ", __FUNCTION__); + } + + if (waitpid(gunzip_pid, NULL, 0) == -1) { + perror_msg("%s wait: ", __FUNCTION__); + } +} diff --git a/libbb/unzip.c b/libbb/unzip.c index 08c17d4..20a4d74 100644 --- a/libbb/unzip.c +++ b/libbb/unzip.c @@ -1005,19 +1005,3 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) return exit_code; } - -/* - * This needs access to global variables wondow and crc_table, so its not in its own file. - */ -extern void gz_close(int gunzip_pid) -{ - if (kill(gunzip_pid, SIGTERM) == -1) { - error_msg_and_die("*** Couldnt kill old gunzip process *** aborting"); - } - - if (waitpid(gunzip_pid, NULL, 0) == -1) { - printf("Couldnt wait ?"); - } - free(window); - free(crc_table); -} -- 2.25.1