Skip to content

Commit 51d5388

Browse files
authored
fix(url): fix leaky Drops for SpecString and CVec (#294)
1 parent a2ddae3 commit 51d5388

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/rust-url/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,10 @@ pub struct CVec<T> {
444444

445445
impl<T> Drop for CVec<T> {
446446
fn drop(&mut self) {
447-
unsafe {
448-
self.ptr.drop_in_place();
447+
if !self.ptr.is_null() && self.cap != 0 {
448+
unsafe {
449+
let _ = Vec::from_raw_parts(self.ptr, self.len, self.cap);
450+
}
449451
}
450452
}
451453
}
@@ -490,8 +492,10 @@ impl<'a> From<&'a SpecString> for &'a str {
490492

491493
impl Drop for SpecString {
492494
fn drop(&mut self) {
493-
unsafe {
494-
self.data.drop_in_place();
495+
if !self.data.is_null() && self.cap != 0 {
496+
unsafe {
497+
let _ = String::from_raw_parts(self.data, self.len, self.cap);
498+
}
495499
}
496500
}
497501
}

0 commit comments

Comments
 (0)