From a69203a95d66595b80891aafc1ca8a59303290d0 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Fri, 18 Oct 2019 09:16:27 +0000 Subject: [PATCH] Debugged all the leaks. Decompression still not working --- src/snapshot.c | 26 +++++++++++++++----------- 1 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/snapshot.c b/src/snapshot.c index 6113c01..53bca9d 100644 --- a/src/snapshot.c +++ b/src/snapshot.c @@ -153,11 +153,11 @@ defstream.opaque = Z_NULL; defstream.avail_in = data_len+1; defstream.next_in = (unsigned char *)data; - fprintf(stderr,"WAS HERE %d\n", data_len); char *compr=(char *)malloc(data_len*sizeof(char)); defstream.avail_out = data_len+1; defstream.next_out = (unsigned char *)compr; - deflateInit(&defstream, Z_BEST_COMPRESSION); + deflateInit(&defstream, 6); +// deflateInit(&defstream, Z_BEST_COMPRESSION); deflate(&defstream, Z_FINISH); deflateEnd(&defstream); *compressed=compr; @@ -173,18 +173,22 @@ return nbase; } -char *ts_compress_intlist(int *data, ts_uint data_len){ - size_t nbase; +char *ts_compress(char *data, ts_uint data_len, ts_uint original_len){ + size_t nbase1, nbase2; char *compr; - size_t number_of_compressed_bytes=ts_compress_data((char *)data, data_len*sizeof(int), &compr); - char *encoded_compressed=base64_encode((unsigned char *)compr,number_of_compressed_bytes,&nbase); + size_t number_of_compressed_bytes=ts_compress_data(data, data_len, &compr); + char *encoded_compressed=base64_encode((unsigned char *)compr,number_of_compressed_bytes,&nbase1); free(compr); - ts_uint header[4]={1, data_len, data_len, nbase}; - char *encoded_header=(char *)base64_encode((unsigned char *)header, 4*sizeof(ts_uint), &nbase); - encoded_header=realloc(encoded_header, 4*sizeof(ts_uint)+strlen(encoded_compressed)); - encoded_header=strcat(encoded_header,encoded_compressed); + ts_uint header[4]={1, original_len, original_len, number_of_compressed_bytes}; + char *encoded_header=(char *)base64_encode((unsigned char *)header, 4*sizeof(ts_uint), &nbase2); + char *return_value=malloc((nbase1+nbase2+1)*sizeof(char)); + strncpy(return_value,encoded_header,nbase2); + strncpy(return_value+nbase2,encoded_compressed,nbase1); + *(return_value+nbase1+nbase2)=0; + printf("Compressed size in bytes= %ld, size of encoded header= %ld, size of encoded compressed= %ld.\n",number_of_compressed_bytes, nbase2, nbase1); free(encoded_compressed); - return encoded_header; + free(encoded_header); + return return_value; } ts_uint ts_decompress_string64(char *b64, ts_uint data_len, char **decompressed){ -- Gitblit v1.9.3