Results 1 to 4 of 4

Thread: HEAP[VariousTests.exe]: Invalid Address specified to RtlValidateHeap.

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default HEAP[VariousTests.exe]: Invalid Address specified to RtlValidateHeap.

    Hello,

    i'm developping a library and a test project to use the library. i have ran into a problem which i can't seem to solve, so i have simplified both the library and the test project, to be able to post an error-reproducible code here.

    The TestClass.h file:
    Qt Code:
    1. #ifndef TestClass_h
    2. #define TestClass_h
    3.  
    4. #include <QString>
    5.  
    6. class RELibOpt TestClass {
    7. public:
    8. // CTor / DCTor.
    9. TestClass ();
    10. virtual ~TestClass ();
    11. // Test methods.
    12. QString gimmeSomethinByCopy () const;
    13. const QString& gimmeSomethinByRef () const;
    14.  
    15. private:
    16. QString _internalString;
    17.  
    18. };
    19.  
    20. #endif
    To copy to clipboard, switch view to plain text mode 
    Test.cpp file:
    Qt Code:
    1. #include "TestClass.h"
    2.  
    3. TestClass::TestClass () {
    4. }
    5. TestClass::~TestClass () {
    6. }
    7.  
    8. QString TestClass::gimmeSomethinByCopy () const {
    9. return QString("Toto");
    10. }
    11.  
    12. const QString& TestClass::gimmeSomethinByRef () const {
    13. return _internalString;
    14. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp file:[code]#include <QCoreApplication>
    #include "TestClass.h"

    #pragma comment (lib, "RELibrary.lib")

    int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);
    // Instanciate the DLL exposed class.
    TestClass anObject;
    // Scope creation, on purpose.
    if (true) {
    // The method "QString DLLExportedClass::giveMeSomethin()" returns a QString, so it's copied...
    QString szTest = anObject.gimmeSomethinByCopy();
    } // CRASH HERE.
    // Scope creation, on purpose.
    if (true) {
    // The method "const QString& DLLExportedClass::giveMeSomethinInternalByRef() const" returns by ref!
    const QString szTest = anObject.gimmeSomethinByRef();
    } // NO CRASH HERE!
    }[code]

    The TestClass library is compiled using the options:
    Qt Code:
    1. RELibOpt=__declspec(dllexport)
    2. DEBUG
    3. _DEBUG
    4. QT_LARGEFILE_SUPPORT
    5. QT_THREAD_SUPPORT
    6. QT_CORE_LIB
    7. QT_GUI_LIB
    To copy to clipboard, switch view to plain text mode 

    The main.cpp (Test project) is compiled using the options:
    Qt Code:
    1. RELibOpt=__declspec(dllimport)
    2. DEBUG
    3. _DEBUG
    4. QT_LARGEFILE_SUPPORT
    5. QT_THREAD_SUPPORT
    6. QT_GUI_LIB
    7. QT_CORE_LIB
    To copy to clipboard, switch view to plain text mode 

    My setup is Windows, Visual Studio 2008, Qt OpenSource 4.6.2 (Qt/bin is in my path).
    As you can see, my library is loaded, the class is instanciated, the methods are called WITHOUT ERROR.
    But in the case of a return - by - copy QString (Or any other Qt object), i get the fault when exiting the scope the QString was retrieved.

    If i invert the blocs in the main, the faulty one remains the same (The return by ref doesn't crash at exit of scope).

    Call stack:
    Qt Code:
    1. ntdll.dll!7c90120e()
    2. [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
    3. ntdll.dll!7c96e139()
    4. ntdll.dll!7c96e576()
    5. ntdll.dll!7c9622e8()
    6. kernel32.dll!7c85f9a7()
    7. > msvcr90d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x003e5cc8) Line 2103 C++
    8. msvcr90d.dll!_free_dbg_nolock(void * pUserData=0x003e5cc8, int nBlockUse=1) Line 1317 + 0x9 bytes C++
    9. msvcr90d.dll!_free_dbg(void * pUserData=0x003e5cc8, int nBlockUse=1) Line 1258 + 0xd bytes C++
    10. msvcr90d.dll!free(void * pUserData=0x003e5cc8) Line 49 + 0xb bytes C++
    11. QtCored4.dll!qFree(void * ptr=0x003e5cc8) Line 60 + 0xa bytes C++
    12. QtCored4.dll!QString::free(QString::Data * d=0x003e5cc8) Line 1108 + 0x9 bytes C++
    13. QtCored4.dll!QString::~QString() Line 869 + 0x23 bytes C++
    14. VariousTests.exe!main(int argc=1, char * * argv=0x003a3670) Line 16 C++
    15. VariousTests.exe!__tmainCRTStartup() Line 266 + 0x19 bytes C
    16. VariousTests.exe!mainCRTStartup() Line 182 C
    17. kernel32.dll!7c817077()
    To copy to clipboard, switch view to plain text mode 

    Output:
    Qt Code:
    1. HEAP[VariousTests.exe]: Invalid Address specified to RtlValidateHeap( 00390000, 003E5CA8 )
    2. Windows has triggered a breakpoint in VariousTests.exe.
    3. This may be due to a corruption of the heap, which indicates a bug in VariousTests.exe or any of the DLLs it has loaded.
    4. This may also be due to the user pressing F12 while VariousTests.exe has focus.
    5. The output window may have more diagnostic information.
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Pierre.

    [EDIT]So you can see what happens, here are two main.cpp and two stack when it crashes. You can clearly see that in both cases, it's when going out of the scope where the COPYed QString was returned that it crashes.[EDIT]

    1st case:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include "TestClass.h"
    3.  
    4. #pragma comment (lib, "RELibrary.lib")
    5.  
    6. int main(int argc, char *argv[]) {
    7. QCoreApplication a(argc, argv);
    8. // On instancie l'objet exposé de la DLL.
    9. TestClass anObject;
    10. // Création volontaire d'un scope.
    11. if (true) {
    12. // La méthode "QString DLLExportedClass::giveMeSomethin()" renvoie une QString, donc assignée en copie...
    13. QString szTest = anObject.gimmeSomethinByCopy();
    14. } // Ca plante!
    15. // Création volontaire d'un scope.
    16. if (true) {
    17. // La méthode "const QString& DLLExportedClass::giveMeSomethinInternalByRef() const"...
    18. const QString szTest = anObject.gimmeSomethinByRef();
    19. } // Ca ne plante pas!
    20. }
    To copy to clipboard, switch view to plain text mode 
    Stack:
    Qt Code:
    1. ntdll.dll!7c90120e()
    2. [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
    3. ntdll.dll!7c96e139()
    4. ntdll.dll!7c96e576()
    5. ntdll.dll!7c9622e8()
    6. kernel32.dll!7c85f9a7()
    7. > msvcr90d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x003e5cc8) Line 2103 C++
    8. msvcr90d.dll!_free_dbg_nolock(void * pUserData=0x003e5cc8, int nBlockUse=1) Line 1317 + 0x9 bytes C++
    9. msvcr90d.dll!_free_dbg(void * pUserData=0x003e5cc8, int nBlockUse=1) Line 1258 + 0xd bytes C++
    10. msvcr90d.dll!free(void * pUserData=0x003e5cc8) Line 49 + 0xb bytes C++
    11. QtCored4.dll!qFree(void * ptr=0x003e5cc8) Line 60 + 0xa bytes C++
    12. QtCored4.dll!QString::free(QString::Data * d=0x003e5cc8) Line 1108 + 0x9 bytes C++
    13. QtCored4.dll!QString::~QString() Line 869 + 0x23 bytes C++
    14. VariousTests.exe!main(int argc=1, char * * argv=0x003a3670) Line 16 C++
    15. VariousTests.exe!__tmainCRTStartup() Line 266 + 0x19 bytes C
    16. VariousTests.exe!mainCRTStartup() Line 182 C
    17. kernel32.dll!7c817077()
    To copy to clipboard, switch view to plain text mode 
    2nd case:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include "TestClass.h"
    3.  
    4. #pragma comment (lib, "RELibrary.lib")
    5.  
    6. int main(int argc, char *argv[]) {
    7. QCoreApplication a(argc, argv);
    8. // On instancie l'objet exposé de la DLL.
    9. TestClass anObject;
    10. // Création volontaire d'un scope.
    11. if (true) {
    12. // La méthode "const QString& DLLExportedClass::giveMeSomethinInternalByRef() const"...
    13. const QString szTest = anObject.gimmeSomethinByRef();
    14. } // Ca ne plante pas!
    15. // Création volontaire d'un scope.
    16. if (true) {
    17. // La méthode "QString DLLExportedClass::giveMeSomethin()" renvoie une QString, donc assignée en copie...
    18. QString szTest = anObject.gimmeSomethinByCopy();
    19. } // Ca plante!
    20. }
    To copy to clipboard, switch view to plain text mode 
    Stack:
    Qt Code:
    1. ntdll.dll!7c90120e()
    2. [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
    3. ntdll.dll!7c96e139()
    4. ntdll.dll!7c96e576()
    5. ntdll.dll!7c9622e8()
    6. kernel32.dll!7c85f9a7()
    7. > msvcr90d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x003e5cc8) Line 2103 C++
    8. msvcr90d.dll!_free_dbg_nolock(void * pUserData=0x003e5cc8, int nBlockUse=1) Line 1317 + 0x9 bytes C++
    9. msvcr90d.dll!_free_dbg(void * pUserData=0x003e5cc8, int nBlockUse=1) Line 1258 + 0xd bytes C++
    10. msvcr90d.dll!free(void * pUserData=0x003e5cc8) Line 49 + 0xb bytes C++
    11. QtCored4.dll!qFree(void * ptr=0x003e5cc8) Line 60 + 0xa bytes C++
    12. QtCored4.dll!QString::free(QString::Data * d=0x003e5cc8) Line 1108 + 0x9 bytes C++
    13. QtCored4.dll!QString::~QString() Line 869 + 0x23 bytes C++
    14. VariousTests.exe!main(int argc=1, char * * argv=0x003a3670) Line 20 C++
    15. VariousTests.exe!__tmainCRTStartup() Line 266 + 0x19 bytes C
    16. VariousTests.exe!mainCRTStartup() Line 182 C
    17. kernel32.dll!7c817077()
    To copy to clipboard, switch view to plain text mode 
    Last edited by hickscorp; 1st April 2010 at 12:31.

  2. #2
    Join Date
    Dec 2006
    Posts
    160
    Thanks
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: HEAP[VariousTests.exe]: Invalid Address specified to RtlValidateHeap.

    Problem solved! The library project for a reason i don't understand (Project generated using the VC Qt addin) was linking against the Qt debugging libs... Not the test project.
    So when returning the copy QString, and then when freeing it, it may have been of 2 different sizes (Debug / Release).
    Problem solved by using the same libraries.

  3. #3
    Join Date
    Jun 2017
    Posts
    1

    Default Re: HEAP[VariousTests.exe]: Invalid Address specified to RtlValidateHeap.

    Hello
    i Have the same probleme and i didn't understand how did you resolve it , can you help me please
    i'm working in VB

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: HEAP[VariousTests.exe]: Invalid Address specified to RtlValidateHeap.

    i'm working in VB
    Visual Basic? Why are you posting in a forum for Qt (which is C++ based) and in response to a 7 year old thread?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Invalid Address specified to RtlFreeHeap
    By abrou in forum Newbie
    Replies: 5
    Last Post: 7th January 2018, 12:06
  2. heap corrupted
    By dognzhe in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2009, 03:54
  3. stack, heap and C#
    By mickey in forum General Programming
    Replies: 8
    Last Post: 20th August 2007, 19:40
  4. Heap Error
    By avis_phoenix in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2006, 04:15
  5. QThread and heap
    By paranoid_android in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2006, 11:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.