Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Corrupted heap space using QtXmld4.dll (VS 2010)
Forum Updated to NodeBB v4.3 + New Features

Corrupted heap space using QtXmld4.dll (VS 2010)

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 6.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    galrub
    wrote on last edited by
    #1

    hello all,

    to make a long story short, here is the code:
    @
    #include <QtXml\qdom.h>
    #include <qdebug.h>
    #include <crw.h>

    int main(int argc, char *argv[])
    {
    QFile f(".\app.xml");
    QString errorMsg;
    int a, b;
    QDomDocument doc( "appsettings" );
    if( !f.open( QIODevice::ReadOnly ) )
    return -1;
    if( !doc.setContent( &f, &errorMsg, &a, &b ) ) //here is where I get the exception
    {
    f.close();
    return -2;
    }
    f.close();
    return 0;
    }
    @

    linking libraries : qtmaind.lib, QtCored4.lib, QtXmld4.lib

    and, th callstack looks like:
    @
    ntdll.dll!77690844()
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
    ntdll.dll!77652a74()
    ntdll.dll!7760cd87()

    QtXmld4.dll!_unlock(int locknum) Line 375 C
    QtXmld4.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1270 + 0x7 bytes C++
    KernelBase.dll!7582468e()
    QtXmld4.dll!_CrtIsValidHeapPointer(const void * pUserData) Line 2036 C++
    QtXmld4.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1322 + 0x9 bytes C++
    QtXmld4.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265 + 0xd bytes C++
    QtXmld4.dll!operator delete(void * pUserData) Line 54 + 0x10 bytes C++
    QtXmld4.dll!QTextDecoder::`scalar deleting destructor'() + 0x21 bytes C++
    QtXmld4.dll!QXmlInputSource::~QXmlInputSource() Line 1357 + 0x22 bytes C++
    QtXmld4.dll!QDomDocument::setContent(QIODevice * dev, bool namespaceProcessing, QString * errorMsg, int * errorLine, int * errorColumn) Line 6755 + 0x31 bytes C++
    QtXmld4.dll!QDomDocument::setContent(QIODevice * dev, QString * errorMsg, int * errorLine, int * errorColumn) Line 6815 C++
    test.exe!main(int argc, char * * argv) Line 17 + 0x19 bytes C++
    test.exe!__tmainCRTStartup() Line 278 + 0x19 bytes C
    test.exe!mainCRTStartup() Line 189 C
    kernel32.dll!76c23677()
    ntdll.dll!775f9f02()
    ntdll.dll!775f9ed5()
    @
    (test.exe is main.cpp)...

    any ideas?
    Thanks,
    G

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      There is no prebuilt binary version of Qt for Visual Studio 2010.

      Did you compile Qt yourself with your VS 2010 or did you use the binary from the download page (which is for VS 2008)?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • G Offline
        G Offline
        galrub
        wrote on last edited by
        #3

        Thank you for the replay.
        I build it myself, the only thing that I changed was the runtime-library flag from /MDd to /MTd so my client (to be) will not need to install the redistribution, but I used the configuration provided with the source for vs2010...

        also, there is no .NET at all here, and, other things, like qtsqlite and gui that I use work perfectly.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Qt and the client code must be compiled and linked with the same linker flags. Do not mix them, otherwise you might end up using two different C/C++ runtimes, which leads to memory corruption when new is called in one implementation and delete in the other.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • G Offline
            G Offline
            galrub
            wrote on last edited by
            #5

            well, they are, all /MTd and /MT (for release)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              Hm, strange. I've no clue what's going wrong there. Maybe someone else will jump in - I don't have VS2010 at hand to do a check myself.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • G Offline
                G Offline
                galrub
                wrote on last edited by
                #7

                I hope so, I will try creating a static library set, just to check, worst case, the XML parsing DLL I'm working on will be created using static libraries.

                anyone... HELP! hahaha

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  Are you sure, your Qt libs were build with /MTd and your binary also for debug and all with /MT for release?
                  It looks (from the defect behavior) very like these do not fit together...

                  How did you change the flags for Qt? Did you use dependency viewer to verify, Qt dies not use the redistributables?

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    galrub
                    wrote on last edited by
                    #9

                    I will build again and run all the nmake output to a file...

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      galrub
                      wrote on last edited by
                      #10

                      according to the build log (all 5Meg of it) there is no indication of any use of -MDd or -MD, just MT.

                      I am not that strong in c/c++ but,
                      according to the callstack we can see that the heap corruption is due to a call of a distructor of the passed &file, or one of it's components. so, we can say that the code itself cannot work with such parameters as -M, because of such call, right?

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        giesbert
                        wrote on last edited by
                        #11

                        Hi,

                        I thopught a bit about this, /MT means link against a static library, that means you add it to all binaries, you create. If you link a dll with /MT, the code is added to that dll. Then you link your executable againtst that and it is also added there. Then you have two different heaps, which leads to that crash. If you use /MT, you MUST use Qt as static library or use /MD (and the vc redistributables).

                        Nokia Certified Qt Specialist.
                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          galrub
                          wrote on last edited by
                          #12

                          thank you Gerolf, after sleeping on it, I came also to the same conclusion.

                          In order for QT to be used in such a way the code must be created with 'awareness' of two (or more) different heap spaces, so, I will be linking QT statically for the xml parser..

                          and, the more I think about it, the more it makes sense also.

                          so, thank you all for the help

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            giesbert
                            wrote on last edited by
                            #13

                            I rhink, you have to link Qt complete statically, or use /MD. The Qt libraries are not memory neutral (which means, memory allocate din one library may be freed in another one).

                            Nokia Certified Qt Specialist.
                            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved