title: QT Image Viewer example, possible memory leak?
body: <p>A <a href="https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html" rel="nofollow noreferrer">Image Viewer Example</a> on the QT documentation website contains the following code snippet:</p>
  <pre><code>ImageViewer::ImageViewer()
     : imageLabel(new QLabel)
     , scrollArea(new QScrollArea)
     , scaleFactor(1)
  {
     imageLabel-&gt;setBackgroundRole(QPalette::Base);
     imageLabel-&gt;setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
     imageLabel-&gt;setScaledContents(true);
  
     scrollArea-&gt;setBackgroundRole(QPalette::Dark);
     scrollArea-&gt;setWidget(imageLabel);
     scrollArea-&gt;setVisible(false);
     setCentralWidget(scrollArea);
  
     createActions();
  
     resize(QGuiApplication::primaryScreen()-&gt;availableSize() * 3 / 5);
  }
  </code></pre>
  <p>Where <code>imageLabel</code> and <code>scrollArea</code> are pointers members to a <code>QLabel</code> and <code>QScrollArea</code> respectively.</p>
  <p>I understand that in the line <code>scrollArea-&gt;setWidget(imageLabel);</code> the scroll area takes ownership of the imageLabel pointer and will delete it when required. Likewise for <code>setCentralWidget(scrollArea);</code> where the window takes ownership of the scrollArea.</p>
  <p>However, during construction, if the <code>imageLabel</code> creation were to succeed, but the <code>scrollArea</code> creation were to fail, would the <code>imageLabel</code> not be leaked?</p>
  <p>If yes, what is the canonical way to solve this?</p>