easylzma icon indicating copy to clipboard operation
easylzma copied to clipboard

Memory leaks!

Open haroel opened this issue 9 years ago • 0 comments

Well,this libs is very easy to use lama. but ,I found there are some Memory leaks problems。In simple.c file

//int simpleCompress(elzma_file_format format, const unsigned char * inData, // size_t inLen, unsigned char ** outData, // size_t * outLen) //{ // int rc; // elzma_compress_handle hand; // // /* allocate compression handle / // hand = elzma_compress_alloc(); // assert(hand != NULL); // // rc = elzma_compress_config(hand, ELZMA_LC_DEFAULT, // ELZMA_LP_DEFAULT, ELZMA_PB_DEFAULT, // 9, (1 << 20) / 1mb /, // format, inLen); // // if (rc != ELZMA_E_OK) { // elzma_compress_free(&hand); // return rc; // }
// // /
now run the compression */ // { // struct dataStream ds; // ds.inData = inData; // ds.inLen = inLen; // ds.outData = NULL; // ds.outLen = 0; // // rc = elzma_compress_run(hand, inputCallback, (void *) &ds, // outputCallback, (void *) &ds, // NULL, NULL); //
// if (rc != ELZMA_E_OK) { // if (ds.outData != NULL) free(ds.outData); // elzma_compress_free(&hand); // return rc; // } // // *outData = ds.outData; // *outLen = ds.outLen; // } // elzma_compress_free(&hand); // return rc; //}

int simpleDecompress(elzma_file_format format, const unsigned char * inData, size_t inLen, unsigned char ** outData, size_t * outLen) { int rc; elzma_decompress_handle hand;

hand = elzma_decompress_alloc();

/* now run the compression */
{
    struct dataStream ds;
    ds.inData = inData;
    ds.inLen = inLen;
    ds.outData = NULL;
    ds.outLen = 0;

    rc = elzma_decompress_run(hand, inputCallback, (void *) &ds,
                              outputCallback, (void *) &ds, format);

    if (rc != ELZMA_E_OK) {
        if (ds.outData != NULL) free(ds.outData);
        elzma_decompress_free(&hand);
        return rc;
    }

    *outData = ds.outData;
    *outLen = ds.outLen;
}
elzma_decompress_free(&hand); //  this line is need

return rc;

}

haroel avatar Aug 21 '15 07:08 haroel