From ba99b81a7849177c5a91b21af2fe1a51429d6da9 Mon Sep 17 00:00:00 2001 From: Pentium44 Date: Mon, 5 Jul 2021 23:26:28 -0700 Subject: [PATCH] Leaky fix to decompress, working fragile example --- src/inc/tar.h | 6 +++--- src/lexer.c | 2 +- src/lz78/lz78.c | 8 ++++++-- src/tar.c | 4 ---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/inc/tar.h b/src/inc/tar.h index 5a6c862..885c0dd 100644 --- a/src/inc/tar.h +++ b/src/inc/tar.h @@ -58,13 +58,13 @@ extern void tar_free_pool (void); // tar entry metadata structure (singly-linked list) struct tar_t { - char original_name[1024]; // original filenme; only availible when writing into a tar + char original_name[100]; // original filenme; only availible when writing into a tar unsigned int begin; // location of data in file (including metadata) union { union { // Pre-POSIX.1-1988 format struct { - char name[1024]; // file name + char name[100]; // file name char mode[8]; // permissions char uid[8]; // user id (octal) char gid[8]; // group id (octal) @@ -72,7 +72,7 @@ struct tar_t { char mtime[12]; // modification time (octal) char check[8]; // sum of unsigned characters in block, with spaces in the check field while calculation is done (octal) char link; // link indicator - char link_name[1024]; // name of linked file + char link_name[100]; // name of linked file }; // UStar format (POSIX IEEE P1003.1) diff --git a/src/lexer.c b/src/lexer.c index e1abe54..183c363 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -536,7 +536,7 @@ char *process_line (char *line) } /* Destroyes the wrapper instance */ - wrapper_destroy(lzwrapper); + //wrapper_destroy(lzwrapper); // open existing file if ((fd = open(filedecout, O_RDWR)) < 0) { diff --git a/src/lz78/lz78.c b/src/lz78/lz78.c index cc342b7..f988664 100644 --- a/src/lz78/lz78.c +++ b/src/lz78/lz78.c @@ -242,7 +242,11 @@ void ht_dictionary_reset(ht_dictionary* d) { void ht_dictionary_destroy(ht_dictionary* d) { if (d != NULL) - free(d); + { + //free(d); + printf("I SHOULD BE FREEING MEMORY RIGHT NOW!\n"); + // This is obviously going to be fixed in due course. + } } dictionary* dictionary_new(uint32_t d_size) { @@ -627,7 +631,7 @@ void lz78_destroy(lz78_instance *lz78) { case LZ78_MODE_DECOMPRESS: d = (lz78_d*)&lz78->state; if (d != NULL) { - dictionary_destroy(d->main); + //dictionary_destroy(d->main); ht_dictionary_destroy(d->secondary); } break; diff --git a/src/tar.c b/src/tar.c index 9eacee8..c74fdcf 100644 --- a/src/tar.c +++ b/src/tar.c @@ -687,15 +687,11 @@ int format_tar_data(struct tar_t * entry, const char * filename, const char verb memset(entry, 0, sizeof(struct tar_t)); strcpy(entry -> original_name, filename); strcpy(entry -> name, filename + move); - printf("Structure sizes: %d %d %d %d %d\n", sizeof(entry -> mode), - sizeof(entry -> uid), sizeof(entry -> gid), sizeof(entry -> size), sizeof(entry -> mtime)); snprintf(entry -> mode, sizeof(entry -> mode), "%07o", st.st_mode & 0777); snprintf(entry -> uid, sizeof(entry -> uid), "%07o", st.st_uid); snprintf(entry -> gid, sizeof(entry -> gid), "%07o", st.st_gid); snprintf(entry -> size, sizeof(entry -> size), "%011o", (int) st.st_size); snprintf(entry -> mtime, sizeof(entry -> mtime), "%011o", (int) st.st_mtime); - printf("%07o%07o%07o%011o%011o\n", st.st_mode & 0777, st.st_uid, st.st_gid, - (int) st.st_size, (int) st.st_mtime); strncpy(entry -> group, "None", 5); // default value memcpy(entry -> ustar, "ustar \x00", 8);