From c11dd0eae09df4982459a34d764910d0501f2ae2 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sat, 1 Aug 2020 21:38:07 +0200 Subject: Improve code structure […] - create a dedicated "usage" macro to reuse - add various checks in the case no memory is available - fix cwd fetching check - correctly free json_objects to remove all existing leaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tar.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/tar.c') diff --git a/src/tar.c b/src/tar.c index b2f4ba5..8894676 100644 --- a/src/tar.c +++ b/src/tar.c @@ -28,7 +28,7 @@ static int copy_data(struct archive* ar, struct archive* aw) void extract(const char* filename, const char* outputdir) { char cwd[256]; - getcwd(cwd, sizeof(cwd)); + void* err = getcwd(cwd, sizeof(cwd)); if (chdir(outputdir) < 0) { @@ -50,10 +50,12 @@ void extract(const char* filename, const char* outputdir) a = archive_read_new(); archive_read_support_format_all(a); archive_read_support_filter_all(a); + ext = archive_write_disk_new(); archive_write_disk_set_options(ext, flags); archive_write_disk_set_standard_lookup(ext); - if ((r = archive_read_open_filename(a, filename, 10240))) return; + + if ((r = archive_read_open_filename(a, filename, 0x4000))) return; for (;;) { @@ -98,5 +100,5 @@ void extract(const char* filename, const char* outputdir) archive_write_close(ext); archive_write_free(ext); - if (cwd != NULL) chdir(cwd); + if (err) chdir(cwd); } -- cgit v1.2.3