Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-20347

QStringList -> NSMutableArray conversion memory leak

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • 5.3.0
    • 4.7.3
    • None
    • Mac OS X 10.6.8
    • 66178447e91f56eaeaee203171b9355399d3bb5c

    Description

      NSString not released after it is added to the NSMutableArray.

      The code we have in qt_cocoa_helpers_mac.mm

      void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list)
      {
          NSMutableArray *result = [NSMutableArray arrayWithCapacity:list.size()];
          for (int i=0; i<list.size(); ++i){
              [result addObject:reinterpret_cast<const NSString *>(QCFString::toCFStringRef(list[i]))]; //Here is a leak!
          }
          return result;
      }
      

      It should use another function from the helper to do the QString -> NSString conversion:

      void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list)
      {
          NSMutableArray *result = [NSMutableArray arrayWithCapacity:list.size()];
          for (int i=0; i<list.size(); ++i){
              [result addObject:qt_mac_QStringToNSString(list[i])]; //Now leak is gone!(If the autorelease pool is used, but I think it is)
          }
          return result;
      }
      

      the same is applicable for -(void)registerDragTypes in qcocoasharedwindowmethods_mac_p.h and maybe for other places which I didn't find.

      P.S. Leak was found with Instruments tool.

      Attachments

        For Gerrit Dashboard: QTBUG-20347
        # Subject Branch Project Status CR V

        Activity

          People

            sorvig Morten Sørvig
            ixsci Eugene Shcherbina
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes