Skip to content

Commit 89822c3

Browse files
mxsmCopilot
andauthored
Update rocketmq-store/src/ha/default_ha_client.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fec9c6c commit 89822c3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

rocketmq-store/src/ha/default_ha_client.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)