File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,10 @@ pub struct RMain {
229
229
230
230
/// Banner output accumulated during startup
231
231
r_banner : String ,
232
+
233
+ /// Raw error buffer provided to `Rf_error()` when throwing `r_read_console()` errors.
234
+ /// Stored in `RMain` to avoid memory leakage when `Rf_error()` jumps.
235
+ r_error_buffer : Option < CString > ,
232
236
}
233
237
234
238
/// Represents the currently active execution request from the frontend. It
@@ -564,6 +568,7 @@ impl RMain {
564
568
positron_ns : None ,
565
569
pending_lines : Vec :: new ( ) ,
566
570
r_banner : String :: new ( ) ,
571
+ r_error_buffer : None ,
567
572
}
568
573
}
569
574
@@ -1951,17 +1956,12 @@ pub extern "C" fn r_read_console(
1951
1956
return 0 ;
1952
1957
} ,
1953
1958
ConsoleResult :: Error ( err) => {
1954
- // Save error message to a global buffer to avoid leaking memory
1959
+ // Save error message to `RMain`'s buffer to avoid leaking memory
1955
1960
// when `Rf_error()` jumps. Some gymnastics are required to deal
1956
1961
// with the possibility of `CString` conversion failure since the
1957
1962
// error message comes from the frontend and might be corrupted.
1958
- static mut ERROR_BUF : Option < CString > = None ;
1959
-
1960
- unsafe {
1961
- ERROR_BUF = Some ( new_cstring ( format ! ( "\n {err}" ) ) ) ;
1962
- }
1963
-
1964
- unsafe { Rf_error ( ERROR_BUF . as_ref ( ) . unwrap ( ) . as_ptr ( ) ) } ;
1963
+ main. r_error_buffer = Some ( new_cstring ( format ! ( "\n {err}" ) ) ) ;
1964
+ unsafe { Rf_error ( main. r_error_buffer . as_ref ( ) . unwrap ( ) . as_ptr ( ) ) } ;
1965
1965
} ,
1966
1966
} ;
1967
1967
}
You can’t perform that action at this time.
0 commit comments