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

Routine name 'free' conflicts with Visual Studio leak detection

    XMLWordPrintable

Details

    • Task
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.5.1
    • Core: Other
    • None
    • Windows

    Description

      To report leaks, Microsoft uses defines to change memory allocation routines to a debug variant.

      https://learn.microsoft.com/en-us/cpp/c-runtime-library/crtdbg-map-alloc?view=msvc-170

       

      The define is _CRTDBG_MAP_ALLOC

       

      There is a conflict in the qhash.h file.  It uses 'free' as a function name.  

       

       
      
          #ifdef _CRTDBG_MAP_ALLOC
              #define calloc(c, s)       _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
              #define _expand(p, s)      _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
              #define free(p)            _free_dbg(p, _NORMAL_BLOCK)
       
      

       

       

       
      template <typename T>
      struct MultiNodeChain
      {
          T value;
          MultiNodeChain *next = nullptr;
          ~MultiNodeChain()
          {
          }
          qsizetype free() noexcept(std::is_nothrow_destructible_v<T>)
          {
              qsizetype nEntries = 0;
              MultiNodeChain *e = this;
              while (e) {
                  MultiNodeChain *n = e->next;
                  ++nEntries;
                  delete e;
                  e = n;
              }
              return  nEntries;
          } 

      I could undefine it to include the file, but that can miss  memory functions and create false reports.

       

       
      #ifdef _CRTDBG_MAP_ALLOC
      #undef _CRTDBG_MAP_ALLOC
      #include <QHash>
      #define _CRTDBG_MAP_ALLOC
      #endif
       
      

       

      It would help if the free function was renamed.

       

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              thiago Thiago Macieira
              doug_rogers Doug Rogers
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes