File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -674,8 +674,17 @@ impl HAClient for DefaultHAClient {
674674
675675 /// Update master address
676676 fn update_master_address ( & self , new_address : & str ) {
677- let addresss = Box :: into_raw ( Box :: new ( new_address. to_string ( ) ) ) ;
678- self . master_address . store ( addresss, Ordering :: SeqCst ) ;
677+ // Safely free the old pointer before storing the new one
678+ let old_address = self . master_address . load ( Ordering :: SeqCst ) ;
679+ if !old_address. is_null ( ) {
680+ unsafe {
681+ // Convert the old pointer back into a Box to free the memory
682+ let _ = Box :: from_raw ( old_address) ;
683+ }
684+ }
685+ // Store the new address
686+ let new_address_ptr = Box :: into_raw ( Box :: new ( new_address. to_string ( ) ) ) ;
687+ self . master_address . store ( new_address_ptr, Ordering :: SeqCst ) ;
679688 }
680689
681690 fn update_ha_master_address ( & self , new_address : & str ) {
You can’t perform that action at this time.
0 commit comments