From bcfd47c28db9a7781fdf66cf79b916e2ec66f78a Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Wed, 11 Sep 2024 16:31:23 +0200 Subject: [PATCH] fix for setting object locations to avoid use-after-free situation --- src/Obj.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Obj.cc b/src/Obj.cc index a3b36dee76..5e346fead9 100644 --- a/src/Obj.cc +++ b/src/Obj.cc @@ -130,11 +130,14 @@ bool Obj::SetLocationInfo(const detail::Location* start, const detail::Location* // We already have a better location, so don't use this one. return true; - delete location; - - location = + auto new_location = new detail::Location(start->filename, start->first_line, end->last_line, start->first_column, end->last_column); + // Don't delete this until we've constructed the new location, in case + // "start" or "end" are our own location. + delete location; + location = new_location; + return true; }