Skip to content

Commit

Permalink
Don't double free embedded, unsized slices
Browse files Browse the repository at this point in the history
Thanks to @eddyb for finding the bug.

Closes #16826 (I hope)
  • Loading branch information
nrc committed Aug 29, 2014
1 parent dee8423 commit 415d7e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/glue.rs
Expand Up @@ -403,11 +403,11 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
ty::ty_uniq(content_ty) => {
match ty::get(content_ty).sty {
ty::ty_vec(ty, None) => {
tvec::make_drop_glue_unboxed(bcx, v0, ty)
tvec::make_drop_glue_unboxed(bcx, v0, ty, true)
}
ty::ty_str => {
let unit_ty = ty::sequence_element_type(bcx.tcx(), t);
tvec::make_drop_glue_unboxed(bcx, v0, unit_ty)
tvec::make_drop_glue_unboxed(bcx, v0, unit_ty, true)
}
ty::ty_trait(..) => {
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
Expand Down Expand Up @@ -507,7 +507,7 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
None);
bcx
}
ty::ty_vec(ty, None) => tvec::make_drop_glue_unboxed(bcx, v0, ty),
ty::ty_vec(ty, None) => tvec::make_drop_glue_unboxed(bcx, v0, ty, false),
_ => {
assert!(ty::type_is_sized(bcx.tcx(), t));
if ty::type_needs_drop(bcx.tcx(), t) &&
Expand Down
18 changes: 12 additions & 6 deletions src/librustc/middle/trans/tvec.rs
Expand Up @@ -54,25 +54,31 @@ pub fn pointer_add_byte(bcx: &Block, ptr: ValueRef, bytes: ValueRef) -> ValueRef
pub fn make_drop_glue_unboxed<'a>(
bcx: &'a Block<'a>,
vptr: ValueRef,
unit_ty: ty::t)
unit_ty: ty::t,
should_deallocate: bool)
-> &'a Block<'a> {
let not_null = IsNotNull(bcx, vptr);
with_cond(bcx, not_null, |bcx| {
let tcx = bcx.tcx();
let _icx = push_ctxt("tvec::make_drop_glue_unboxed");

let len = get_len(bcx, vptr);
let dataptr = get_dataptr(bcx, vptr);
let bcx = if ty::type_needs_drop(tcx, unit_ty) {
let len = get_len(bcx, vptr);
iter_vec_raw(bcx, dataptr, unit_ty, len, glue::drop_ty)
} else {
bcx
};

let not_null = IsNotNull(bcx, dataptr);
with_cond(bcx, not_null, |bcx| {
glue::trans_exchange_free(bcx, dataptr, 0, 8)
})
if should_deallocate {
let not_null = IsNotNull(bcx, dataptr);
with_cond(bcx, not_null, |bcx| {
// FIXME: #13994: the old `Box<[T]>` will not support sized deallocation
glue::trans_exchange_free(bcx, dataptr, 0, 8)
})
} else {
bcx
}
})
}

Expand Down

9 comments on commit 415d7e8

@bors
Copy link
Contributor

@bors bors commented on 415d7e8 Aug 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pnkfelix, nikomatsakis
at nrc@415d7e8

@bors
Copy link
Contributor

@bors bors commented on 415d7e8 Aug 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/dst-bug-4 = 415d7e8 into auto

@bors
Copy link
Contributor

@bors bors commented on 415d7e8 Aug 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/dst-bug-4 = 415d7e8 merged ok, testing candidate = f35a796b

@bors
Copy link
Contributor

@bors bors commented on 415d7e8 Aug 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 415d7e8 Aug 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pnkfelix, nikomatsakis
at nrc@415d7e8

@bors
Copy link
Contributor

@bors bors commented on 415d7e8 Aug 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/dst-bug-4 = 415d7e8 into auto

@bors
Copy link
Contributor

@bors bors commented on 415d7e8 Aug 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/dst-bug-4 = 415d7e8 merged ok, testing candidate = 6025926

@bors
Copy link
Contributor

@bors bors commented on 415d7e8 Aug 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 6025926

Please sign in to comment.