Leaky fix to decompress, working fragile example

This commit is contained in:
Pentium44 2021-07-05 23:26:28 -07:00
parent 76c042e0cb
commit ba99b81a78
4 changed files with 10 additions and 10 deletions

View File

@ -58,13 +58,13 @@ extern void tar_free_pool (void);
// tar entry metadata structure (singly-linked list) // tar entry metadata structure (singly-linked list)
struct tar_t { 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) unsigned int begin; // location of data in file (including metadata)
union { union {
union { union {
// Pre-POSIX.1-1988 format // Pre-POSIX.1-1988 format
struct { struct {
char name[1024]; // file name char name[100]; // file name
char mode[8]; // permissions char mode[8]; // permissions
char uid[8]; // user id (octal) char uid[8]; // user id (octal)
char gid[8]; // group id (octal) char gid[8]; // group id (octal)
@ -72,7 +72,7 @@ struct tar_t {
char mtime[12]; // modification time (octal) 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 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; // link indicator
char link_name[1024]; // name of linked file char link_name[100]; // name of linked file
}; };
// UStar format (POSIX IEEE P1003.1) // UStar format (POSIX IEEE P1003.1)

View File

@ -536,7 +536,7 @@ char *process_line (char *line)
} }
/* Destroyes the wrapper instance */ /* Destroyes the wrapper instance */
wrapper_destroy(lzwrapper); //wrapper_destroy(lzwrapper);
// open existing file // open existing file
if ((fd = open(filedecout, O_RDWR)) < 0) { if ((fd = open(filedecout, O_RDWR)) < 0) {

View File

@ -242,7 +242,11 @@ void ht_dictionary_reset(ht_dictionary* d) {
void ht_dictionary_destroy(ht_dictionary* d) { void ht_dictionary_destroy(ht_dictionary* d) {
if (d != NULL) 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) { dictionary* dictionary_new(uint32_t d_size) {
@ -627,7 +631,7 @@ void lz78_destroy(lz78_instance *lz78) {
case LZ78_MODE_DECOMPRESS: case LZ78_MODE_DECOMPRESS:
d = (lz78_d*)&lz78->state; d = (lz78_d*)&lz78->state;
if (d != NULL) { if (d != NULL) {
dictionary_destroy(d->main); //dictionary_destroy(d->main);
ht_dictionary_destroy(d->secondary); ht_dictionary_destroy(d->secondary);
} }
break; break;

View File

@ -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)); memset(entry, 0, sizeof(struct tar_t));
strcpy(entry -> original_name, filename); strcpy(entry -> original_name, filename);
strcpy(entry -> name, filename + move); 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 -> mode, sizeof(entry -> mode), "%07o", st.st_mode & 0777);
snprintf(entry -> uid, sizeof(entry -> uid), "%07o", st.st_uid); snprintf(entry -> uid, sizeof(entry -> uid), "%07o", st.st_uid);
snprintf(entry -> gid, sizeof(entry -> gid), "%07o", st.st_gid); snprintf(entry -> gid, sizeof(entry -> gid), "%07o", st.st_gid);
snprintf(entry -> size, sizeof(entry -> size), "%011o", (int) st.st_size); snprintf(entry -> size, sizeof(entry -> size), "%011o", (int) st.st_size);
snprintf(entry -> mtime, sizeof(entry -> mtime), "%011o", (int) st.st_mtime); 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 strncpy(entry -> group, "None", 5); // default value
memcpy(entry -> ustar, "ustar \x00", 8); memcpy(entry -> ustar, "ustar \x00", 8);