From c2cbc7df84951541b29200c3a6ade3163fb815ae Mon Sep 17 00:00:00 2001 From: Fengwei Yin Date: Thu, 24 May 2012 16:47:48 +0800 Subject: back port upstream patch This patch is from Chromium project. It's used to handle potential issue in scoped_refptr. This is upstream patch porting and the original link is: http://codereview.chromium.org/9021020/ unittest change was not included. Change-Id: I14ce3df0653ff29713f38eceaf07e9b409cfaedc Author: Fengwei Yin Singed-off-by: Shuo Gao Signed-off-by: Bruce Beare Signed-off-by: Jack Ren Author-tracking-BZ: 37500 --- base/memory/ref_counted.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h index 1207ed4..e35264b 100644 --- a/base/memory/ref_counted.h +++ b/base/memory/ref_counted.h @@ -260,9 +260,10 @@ class scoped_refptr { // AddRef first so that self assignment should work if (p) p->AddRef(); - if (ptr_ ) - ptr_ ->Release(); + T* old_ptr = ptr_; ptr_ = p; + if (old_ptr) + old_ptr ->Release(); return *this; } -- cgit v1.1