@@ -1251,8 +1251,11 @@ unsafe fn ZSTD_cwksp_create(
12511251#[ inline]
12521252unsafe fn ZSTD_cwksp_free ( ws : * mut ZSTD_cwksp , customMem : ZSTD_customMem ) {
12531253 let ptr = ( * ws) . workspace ;
1254+ let size = ( * ws)
1255+ . workspaceEnd
1256+ . byte_offset_from_unsigned ( ( * ws) . workspace ) ;
12541257 ptr:: write_bytes ( ws as * mut u8 , 0 , :: core:: mem:: size_of :: < ZSTD_cwksp > ( ) ) ;
1255- ZSTD_customFree ( ptr, customMem) ;
1258+ ZSTD_customFree ( ptr, size , customMem) ;
12561259}
12571260#[ inline]
12581261unsafe fn ZSTD_cwksp_move ( dst : * mut ZSTD_cwksp , src : * mut ZSTD_cwksp ) {
@@ -1705,7 +1708,11 @@ pub unsafe extern "C" fn ZSTD_initStaticCCtx(
17051708 cctx
17061709}
17071710unsafe fn ZSTD_clearAllDicts ( cctx : * mut ZSTD_CCtx ) {
1708- ZSTD_customFree ( ( * cctx) . localDict . dictBuffer , ( * cctx) . customMem ) ;
1711+ ZSTD_customFree (
1712+ ( * cctx) . localDict . dictBuffer ,
1713+ ( * cctx) . localDict . dictSize ,
1714+ ( * cctx) . customMem ,
1715+ ) ;
17091716 ZSTD_freeCDict ( ( * cctx) . localDict . cdict ) ;
17101717 ptr:: write_bytes (
17111718 & mut ( * cctx) . localDict as * mut ZSTD_localDict as * mut u8 ,
@@ -1746,7 +1753,11 @@ pub unsafe extern "C" fn ZSTD_freeCCtx(cctx: *mut ZSTD_CCtx) -> size_t {
17461753 ZSTD_cwksp_owns_buffer ( & ( * cctx) . workspace , cctx as * const core:: ffi:: c_void ) ;
17471754 ZSTD_freeCCtxContent ( cctx) ;
17481755 if cctxInWorkspace == 0 {
1749- ZSTD_customFree ( cctx as * mut core:: ffi:: c_void , ( * cctx) . customMem ) ;
1756+ ZSTD_customFree (
1757+ cctx as * mut core:: ffi:: c_void ,
1758+ :: core:: mem:: size_of :: < ZSTD_CCtx > ( ) ,
1759+ ( * cctx) . customMem ,
1760+ ) ;
17501761 }
17511762 0
17521763}
@@ -1965,7 +1976,11 @@ pub unsafe extern "C" fn ZSTD_freeCCtxParams(params: *mut ZSTD_CCtx_params) -> s
19651976 if params. is_null ( ) {
19661977 return 0 ;
19671978 }
1968- ZSTD_customFree ( params as * mut core:: ffi:: c_void , ( * params) . customMem ) ;
1979+ ZSTD_customFree (
1980+ params as * mut core:: ffi:: c_void ,
1981+ :: core:: mem:: size_of :: < ZSTD_CCtx_params > ( ) ,
1982+ ( * params) . customMem ,
1983+ ) ;
19691984 0
19701985}
19711986#[ cfg_attr( feature = "export-symbols" , export_name = crate :: prefix!( ZSTD_CCtxParams_reset ) ) ]
@@ -5564,7 +5579,7 @@ pub unsafe extern "C" fn ZSTD_generateSequences(
55645579 seqCollector. maxSequences = outSeqsSize;
55655580 ( * zc) . seqCollector = seqCollector;
55665581 let ret = ZSTD_compress2 ( zc, dst, dstCapacity, src, srcSize) ;
5567- ZSTD_customFree ( dst, ZSTD_customMem :: default ( ) ) ;
5582+ ZSTD_customFree ( dst, dstCapacity , ZSTD_customMem :: default ( ) ) ;
55685583 let err_code_1 = ret;
55695584 if ERR_isError ( err_code_1) {
55705585 return err_code_1;
@@ -8657,7 +8672,6 @@ unsafe fn ZSTD_createCDict_advanced_internal(
86578672 isStatic : ZSTD_cwksp_dynamic_alloc ,
86588673 } ;
86598674 if workspace. is_null ( ) {
8660- ZSTD_customFree ( workspace, customMem) ;
86618675 return core:: ptr:: null_mut ( ) ;
86628676 }
86638677 ZSTD_cwksp_init ( & mut ws, workspace, workspaceSize, ZSTD_cwksp_dynamic_alloc ) ;
@@ -8765,7 +8779,6 @@ pub unsafe extern "C" fn ZSTD_createCDict_advanced2(
87658779 targetLength : 0 ,
87668780 strategy : 0 ,
87678781 } ;
8768- let mut cdict = core:: ptr:: null_mut :: < ZSTD_CDict > ( ) ;
87698782 if cctxParams. enableDedicatedDictSearch != 0 {
87708783 cParams = ZSTD_dedicatedDictSearch_getCParams ( cctxParams. compressionLevel , dictSize) ;
87718784 ZSTD_overrideCParams ( & mut cParams, & cctxParams. cParams ) ;
@@ -8789,7 +8802,7 @@ pub unsafe extern "C" fn ZSTD_createCDict_advanced2(
87898802 cctxParams. cParams = cParams;
87908803 cctxParams. useRowMatchFinder =
87918804 ZSTD_resolveRowMatchFinderMode ( cctxParams. useRowMatchFinder , & cParams) ;
8792- cdict = ZSTD_createCDict_advanced_internal (
8805+ let cdict = ZSTD_createCDict_advanced_internal (
87938806 dictSize,
87948807 dictLoadMethod,
87958808 cctxParams. cParams ,
@@ -8880,7 +8893,11 @@ pub unsafe extern "C" fn ZSTD_freeCDict(cdict: *mut ZSTD_CDict) -> size_t {
88808893 ZSTD_cwksp_owns_buffer ( & ( * cdict) . workspace , cdict as * const core:: ffi:: c_void ) ;
88818894 ZSTD_cwksp_free ( & mut ( * cdict) . workspace , cMem) ;
88828895 if cdictInWorkspace == 0 {
8883- ZSTD_customFree ( cdict as * mut core:: ffi:: c_void , cMem) ;
8896+ ZSTD_customFree (
8897+ cdict as * mut core:: ffi:: c_void ,
8898+ ( * cdict) . dictContentSize ,
8899+ cMem,
8900+ ) ;
88848901 }
88858902 0
88868903}
@@ -8898,18 +8915,14 @@ pub unsafe extern "C" fn ZSTD_initStaticCDict(
88988915 ZSTD_resolveRowMatchFinderMode ( ZSTD_ParamSwitch_e :: ZSTD_ps_auto , & cParams) ;
88998916 let matchStateSize = ZSTD_sizeof_matchState ( & cParams, useRowMatchFinder, 1 , 0 ) ;
89008917 let neededSize = ( ZSTD_cwksp_alloc_size ( :: core:: mem:: size_of :: < ZSTD_CDict > ( ) ) )
8901- . wrapping_add (
8902- if dictLoadMethod as core:: ffi:: c_uint
8903- == ZSTD_dlm_byRef as core:: ffi:: c_int as core:: ffi:: c_uint
8904- {
8905- 0
8906- } else {
8907- ZSTD_cwksp_alloc_size ( ZSTD_cwksp_align (
8908- dictSize,
8909- :: core:: mem:: size_of :: < * mut core:: ffi:: c_void > ( ) ,
8910- ) )
8911- } ,
8912- )
8918+ . wrapping_add ( if dictLoadMethod == ZSTD_dlm_byRef {
8919+ 0
8920+ } else {
8921+ ZSTD_cwksp_alloc_size ( ZSTD_cwksp_align (
8922+ dictSize,
8923+ :: core:: mem:: size_of :: < * mut core:: ffi:: c_void > ( ) ,
8924+ ) )
8925+ } )
89138926 . wrapping_add ( ZSTD_cwksp_alloc_size ( HUF_WORKSPACE_SIZE as size_t ) )
89148927 . wrapping_add ( matchStateSize) ;
89158928 let mut cdict = core:: ptr:: null_mut :: < ZSTD_CDict > ( ) ;
0 commit comments