<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>239338</bug_id>
          
          <creation_ts>2022-04-14 08:55:31 -0700</creation_ts>
          <short_desc>False positive warning when building RefCounter test with GCC 12</short_desc>
          <delta_ts>2022-05-13 07:54:54 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Tools / Tests</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Catanzaro">mcatanzaro</reporter>
          <assigned_to name="Michael Catanzaro">mcatanzaro</assigned_to>
          <cc>mcatanzaro</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1861515</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-04-14 08:55:31 -0700</bug_when>
    <thetext>TODO: I should investigate this more closely

[1736/6690] Building CXX object Tools/TestWebKitAPI/CMakeFiles/TestWTF.dir/Tests/WTF/RefCounter.cpp.o
In file included from /home/mcatanzaro/Projects/WebKit/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp:29:
In member function ‘void WTF::RefCounter&lt;T&gt;::Count::deref() [with T = TestWebKitAPI::TestCounterType]’,
    inlined from ‘static void WTF::DefaultRefDerefTraits&lt; &lt;template-parameter-1-1&gt; &gt;::derefIfNotNull(T*) [with T = WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefPtr.h:42:23,
    inlined from ‘WTF::RefPtr&lt;T, PtrTraits, RefDerefTraits&gt;&amp; WTF::RefPtr&lt;T, &lt;template-parameter-1-2&gt;, &lt;template-parameter-1-3&gt; &gt;::operator=(std::nullptr_t) [with T = WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count; _PtrTraits = WTF::RawPtrTraits&lt;WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count&gt;; _RefDerefTraits = WTF::DefaultRefDerefTraits&lt;WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count&gt;]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefPtr.h:160:22,
    inlined from ‘virtual void TestWebKitAPI::WTF_RefCounter_Test::TestBody()’ at /home/mcatanzaro/Projects/WebKit/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp:152:19:
/home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefCounter.h:101:9: warning: pointer used after ‘void operator delete(void*, std::size_t)’ [-Wuse-after-free]
  101 |     if (m_refCounter &amp;&amp; m_refCounter-&gt;m_valueDidChange) {
      |         ^~~~~~~~~~~~
In member function ‘void WTF::RefCounter&lt;T&gt;::Count::refCounterWasDeleted() [with T = TestWebKitAPI::TestCounterType]’,
    inlined from ‘void WTF::RefCounter&lt;T&gt;::Count::deref() [with T = TestWebKitAPI::TestCounterType]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefCounter.h:115:13,
    inlined from ‘static void WTF::DefaultRefDerefTraits&lt; &lt;template-parameter-1-1&gt; &gt;::derefIfNotNull(T*) [with T = WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefPtr.h:42:23,
    inlined from ‘WTF::RefPtr&lt;T, PtrTraits, RefDerefTraits&gt;&amp; WTF::RefPtr&lt;T, &lt;template-parameter-1-2&gt;, &lt;template-parameter-1-3&gt; &gt;::operator=(std::nullptr_t) [with T = WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count; _PtrTraits = WTF::RawPtrTraits&lt;WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count&gt;; _RefDerefTraits = WTF::DefaultRefDerefTraits&lt;WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count&gt;]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefPtr.h:160:22,
    inlined from ‘virtual void TestWebKitAPI::WTF_RefCounter_Test::TestBody()’ at /home/mcatanzaro/Projects/WebKit/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp:150:19:
/home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefCounter.h:128:9: note: call to ‘void operator delete(void*, std::size_t)’ here
  128 |         delete this;
      |         ^~~~~~~~~~~
In member function ‘void WTF::RefCounter&lt;T&gt;::Count::deref() [with T = TestWebKitAPI::TestCounterType]’,
    inlined from ‘static void WTF::DefaultRefDerefTraits&lt; &lt;template-parameter-1-1&gt; &gt;::derefIfNotNull(T*) [with T = WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefPtr.h:42:23,
    inlined from ‘WTF::RefPtr&lt;T, PtrTraits, RefDerefTraits&gt;&amp; WTF::RefPtr&lt;T, &lt;template-parameter-1-2&gt;, &lt;template-parameter-1-3&gt; &gt;::operator=(std::nullptr_t) [with T = WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count; _PtrTraits = WTF::RawPtrTraits&lt;WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count&gt;; _RefDerefTraits = WTF::DefaultRefDerefTraits&lt;WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count&gt;]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefPtr.h:160:22,
    inlined from ‘virtual void TestWebKitAPI::WTF_RefCounter_Test::TestBody()’ at /home/mcatanzaro/Projects/WebKit/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp:152:19:
/home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefCounter.h:99:7: warning: pointer used after ‘void operator delete(void*, std::size_t)’ [-Wuse-after-free]
   99 |     --m_value;
      |       ^~~~~~~
In member function ‘void WTF::RefCounter&lt;T&gt;::Count::refCounterWasDeleted() [with T = TestWebKitAPI::TestCounterType]’,
    inlined from ‘void WTF::RefCounter&lt;T&gt;::Count::deref() [with T = TestWebKitAPI::TestCounterType]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefCounter.h:115:13,
    inlined from ‘static void WTF::DefaultRefDerefTraits&lt; &lt;template-parameter-1-1&gt; &gt;::derefIfNotNull(T*) [with T = WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefPtr.h:42:23,
    inlined from ‘WTF::RefPtr&lt;T, PtrTraits, RefDerefTraits&gt;&amp; WTF::RefPtr&lt;T, &lt;template-parameter-1-2&gt;, &lt;template-parameter-1-3&gt; &gt;::operator=(std::nullptr_t) [with T = WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count; _PtrTraits = WTF::RawPtrTraits&lt;WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count&gt;; _RefDerefTraits = WTF::DefaultRefDerefTraits&lt;WTF::RefCounter&lt;TestWebKitAPI::TestCounterType&gt;::Count&gt;]’ at /home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefPtr.h:160:22,
    inlined from ‘virtual void TestWebKitAPI::WTF_RefCounter_Test::TestBody()’ at /home/mcatanzaro/Projects/WebKit/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp:150:19:
/home/mcatanzaro/Projects/WebKit/WebKitBuild/GNOME-gtk3/WTF/Headers/wtf/RefCounter.h:128:9: note: call to ‘void operator delete(void*, std::size_t)’ here
  128 |         delete this;
      |         ^~~~~~~~~~~</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1868562</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-05-12 15:12:37 -0700</bug_when>
    <thetext>This warning is a false positive. m_refCounter is nullptr at this point. RefCounter&lt;T&gt;::~RefCounter calls m_count-&gt;refCounterWasDeleted(), which sets m_refCounter = nullptr. It&apos;s a poor man&apos;s WeakPtr, basically. I instrumented the code with some WTFLogAlways and it looks like everything is going fine, so I will suppress this warning.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1868563</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-05-12 15:12:46 -0700</bug_when>
    <thetext>&lt;rdar://problem/93204514&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1868564</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-05-12 15:20:19 -0700</bug_when>
    <thetext>Actually wait, I only checked the first of the two warnings. As usual, I commented too soon.

The second warning relates to m_value, not m_refCounter. The only way this could go wrong is if the Counter object itself is already invalid when its member function is called. I highly doubt that is happening, but will add more instrumentation to check this case as well, just to be completely sure. (If that does happen, then it would explain the first warning as well.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1868570</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-05-12 16:05:18 -0700</bug_when>
    <thetext>I think we&apos;re fine:

// Testing (3g) - deref with callback from 1 -&gt; 0 AFTER RefCounter has been destroyed.
deref: this=0x20cdd10
~Count this=0x20cdd10
// Testing (1b) - Construction without a callback.

The use after free would happen if ~Count were somehow destroyed before Count::deref is called. The opposite is happening. Seems good.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1868593</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-05-12 17:34:35 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/605</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1868762</commentid>
    <comment_count>6</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-05-13 07:54:52 -0700</bug_when>
    <thetext>Committed r294157 (250527@main): &lt;https://commits.webkit.org/250527@main&gt;

Reviewed commits have been landed. Closing PR #605 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>