11use regex:: { Captures , Regex , RegexSet } ;
2-
32use sqlite_loadable:: prelude:: * ;
43use sqlite_loadable:: { api, Error , Result } ;
4+ use std:: os:: raw:: c_void;
55
66// Raw bytes as performance. the string MUST end in the null byte '\0'
77const REGEX_POINTER_NAME : & [ u8 ] = b"regex0\0 " ;
@@ -101,8 +101,9 @@ pub fn regex_from_value_or_cache(
101101 }
102102}
103103
104- use std:: os:: raw:: c_void;
105- unsafe extern "C" fn cleanup ( _arg1 : * mut c_void ) { }
104+ unsafe extern "C" fn cleanup_regex ( arg1 : * mut c_void ) {
105+ drop ( Box :: from_raw ( arg1. cast :: < Regex > ( ) ) )
106+ }
106107
107108pub fn cleanup_regex_value_cached (
108109 context : * mut sqlite3_context ,
@@ -112,15 +113,12 @@ pub fn cleanup_regex_value_cached(
112113 match input_type {
113114 RegexInputType :: Pointer => ( ) ,
114115 RegexInputType :: GetAuxdata => { }
115- RegexInputType :: TextInitial ( at) => {
116- api:: auxdata_set (
117- context,
118- at as i32 ,
119- regex. cast :: < c_void > ( ) ,
120- // TODO memory leak, box not destroyed?
121- Some ( cleanup) ,
122- )
123- }
116+ RegexInputType :: TextInitial ( at) => api:: auxdata_set (
117+ context,
118+ at as i32 ,
119+ regex. cast :: < c_void > ( ) ,
120+ Some ( cleanup_regex) ,
121+ ) ,
124122 }
125123}
126124
0 commit comments