Skip to content

Commit cac8902

Browse files
committed
Remove non-focused memory leaks in alloc doctests for Miri.
1 parent 5569ece commit cac8902

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

alloc/src/rc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ impl<T: ?Sized> Rc<T> {
12871287
///
12881288
/// let five = Rc::from_raw(ptr);
12891289
/// assert_eq!(2, Rc::strong_count(&five));
1290+
/// # // Prevent leaks for Miri.
1291+
/// # Rc::decrement_strong_count(ptr);
12901292
/// }
12911293
/// ```
12921294
#[inline]
@@ -1344,6 +1346,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
13441346
/// let x = Rc::new("hello".to_owned());
13451347
/// let x_ptr = Rc::into_raw(x);
13461348
/// assert_eq!(unsafe { &*x_ptr }, "hello");
1349+
/// # // Prevent leaks for Miri.
1350+
/// # drop(unsafe { Rc::from_raw(x_ptr) });
13471351
/// ```
13481352
#[must_use = "losing the pointer will leak memory"]
13491353
#[stable(feature = "rc_raw", since = "1.17.0")]
@@ -1571,6 +1575,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
15711575
///
15721576
/// let five = Rc::from_raw_in(ptr, System);
15731577
/// assert_eq!(2, Rc::strong_count(&five));
1578+
/// # // Prevent leaks for Miri.
1579+
/// # Rc::decrement_strong_count_in(ptr, System);
15741580
/// }
15751581
/// ```
15761582
#[inline]

alloc/src/sync.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,8 @@ impl<T: ?Sized> Arc<T> {
14281428
/// // the `Arc` between threads.
14291429
/// let five = Arc::from_raw(ptr);
14301430
/// assert_eq!(2, Arc::strong_count(&five));
1431+
/// # // Prevent leaks for Miri.
1432+
/// # Arc::decrement_strong_count(ptr);
14311433
/// }
14321434
/// ```
14331435
#[inline]
@@ -1487,6 +1489,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
14871489
/// let x = Arc::new("hello".to_owned());
14881490
/// let x_ptr = Arc::into_raw(x);
14891491
/// assert_eq!(unsafe { &*x_ptr }, "hello");
1492+
/// # // Prevent leaks for Miri.
1493+
/// # drop(unsafe { Arc::from_raw(x_ptr) });
14901494
/// ```
14911495
#[must_use = "losing the pointer will leak memory"]
14921496
#[stable(feature = "rc_raw", since = "1.17.0")]
@@ -1769,6 +1773,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
17691773
/// // the `Arc` between threads.
17701774
/// let five = Arc::from_raw_in(ptr, System);
17711775
/// assert_eq!(2, Arc::strong_count(&five));
1776+
/// # // Prevent leaks for Miri.
1777+
/// # Arc::decrement_strong_count_in(ptr, System);
17721778
/// }
17731779
/// ```
17741780
#[inline]

0 commit comments

Comments
 (0)