Results 1 to 2 of 2

Thread: runtime error: “*** glibc detected ***: double free or corruption (out)”

  1. #1
    Join Date
    Feb 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default runtime error: “*** glibc detected ***: double free or corruption (out)”

    I have interesting combination of warnings & errors.

    Firstly, when debugging, i get warnings:

    Qt Code:
    1. can't find linker symbol for virtual table for `QFile' value
    2. found `WebCore::JSDocument::JSDocument(JSC::Structure*, WebCore::JSDOMGlobalObject*, WTF::PassRefPtr<WebCore::Document>)' instead
    3. RTTI symbol not found for class 'WebCore::JSHTMLDocument'
    4. RTTI symbol not found for class 'WebCore::JSHTMLDocument'
    5. RTTI symbol not found for class 'WebCore::JSHTMLDocument'
    To copy to clipboard, switch view to plain text mode 
    secondly, i have runtime error:

    Qt Code:
    1. QIODevice::open: File access not specified
    To copy to clipboard, switch view to plain text mode 
    and momently

    Qt Code:
    1. *** glibc detected *** <path>: double free or corruption (out): 0x081f9d00 ***
    To copy to clipboard, switch view to plain text mode 
    Here's the minimal code that causes that errors:

    Files

    In result folder created folder "resources" and in it file "vk.cookie" (everything without quotes).

    Bug.pro

    Qt Code:
    1. QT += core gui webkit network xml
    2.  
    3. TARGET = Bug
    4. TEMPLATE = app
    5.  
    6.  
    7. SOURCES += main.cpp \
    8. api_vk.cpp \
    9. printer.cpp
    10.  
    11. HEADERS += \
    12. api_vk.h \
    13. printer.h
    To copy to clipboard, switch view to plain text mode 

    main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "api_vk.h"
    3. #include "printer.h"
    4.  
    5. int main(int argc, char *argv[]) {
    6. QApplication a(argc, argv);
    7. API_VK *apivk = new API_VK;
    8. apivk->authorise();
    9. Printer *printer = new Printer;
    10. QObject::connect(apivk, SIGNAL(authorisationSucceed()), printer, SLOT(printOK()));
    11. QObject::connect(apivk, SIGNAL(authorisationFailed(QString,QString)), printer, SLOT(printFail()));
    12.  
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    api_vk.h

    Qt Code:
    1. #ifndef API_VK_H
    2. #define API_VK_H
    3.  
    4. #include <QObject>
    5. #include <QTimer>
    6. #include <QUrl>
    7. #include <QtNetwork/QNetworkCookieJar>
    8.  
    9. class QWebView;
    10. class QString;
    11. class QNetworkReply;
    12. class QTimer;
    13. class QNetworkCookie;
    14.  
    15. class API_VK : public QObject
    16. {
    17. Q_OBJECT
    18. public:
    19. explicit API_VK(QObject *parent = 0);
    20.  
    21. signals:
    22. void authorisationFailed(QString error, QString error_description);
    23. void authorisationSucceed();
    24.  
    25. public slots:
    26. void authorise();
    27.  
    28. protected:
    29. void readCookies();
    30. void writeCookies();
    31.  
    32. protected slots:
    33. void newAuthoriseRequest();
    34. void processUrl(QUrl url);
    35.  
    36. private:
    37. static const QString app_id;
    38. static QString access_token;
    39. static qint32 expires_in;
    40. QWebView *messagesPage;
    41. QList<QNetworkCookie> cookies;
    42. QNetworkCookieJar jar;
    43.  
    44. static bool authorised;
    45. };
    46.  
    47. #endif
    To copy to clipboard, switch view to plain text mode 

    api_vk.cpp

    Qt Code:
    1. #include "api_vk.h"
    2. #include <QtGui>
    3. #include <QWebView>
    4. #include <QtNetwork/QNetworkRequest>
    5. #include <QtNetwork/QNetworkAccessManager>
    6. #include <QtNetwork/QNetworkReply>
    7. #include <QtNetwork/QNetworkCookie>
    8. #include <QtNetwork/QNetworkCookieJar>
    9. #include <QString>
    10. #include <QStringList>
    11. #include <QFile>
    12. #include <QTextStream>
    13. #include <QTimer>
    14. #include <QUrl>
    15. #include <QtXml>
    16. #include <QVariant>
    17. #include <QDateTime>
    18. #include <QDebug>
    19.  
    20.  
    21. bool API_VK::authorised = false;
    22. const QString API_VK::app_id = "2783286";
    23. QString API_VK::access_token = "";
    24. int API_VK::expires_in = 0;
    25.  
    26.  
    27. // defining class methods
    28.  
    29. API_VK::API_VK(QObject *parent) :
    30. QObject(parent)
    31. {
    32. }
    33.  
    34. void API_VK::authorise() {
    35. newAuthoriseRequest(); // 1. going here
    36. }
    37.  
    38. void API_VK::newAuthoriseRequest() {
    39. // gets new access_token
    40. // 2. going here
    41.  
    42. messagesPage = new QWebView;
    43. readCookies();
    44. jar.setCookiesFromUrl(cookies, QUrl("http://vk.com"));
    45. messagesPage->page()->networkAccessManager()->setCookieJar(&jar);
    46.  
    47. QUrl url("http://oauth.vk.com/authorize");
    48. url.addQueryItem("client_id", app_id);
    49. url.addQueryItem("scope", "messages");
    50. url.addQueryItem("redirect_uri","http://api.vk.com/blank.html");
    51. url.addQueryItem("display","page");
    52. url.addQueryItem("response_type","token");
    53.  
    54. messagesPage->load(QNetworkRequest(url));
    55. connect(messagesPage, SIGNAL(urlChanged(QUrl)), this, SLOT(processUrl(QUrl)));
    56. messagesPage->show();
    57.  
    58. }
    59.  
    60. void API_VK::processUrl(QUrl url) { // 3. going here
    61. /* firstly we're here when oath.vk.com redirects us to api.vk.com/login...
    62.  * in this case we're exiting at 4.
    63.  * secondly, user logs in, and api.vk.com/login redirects us back to oath.vk.com,
    64.  * where we get access_token, etc
    65.  * and when debugging, we start receiving warnings about "can't find linker symbol" secondly, not firstly
    66.  */
    67.  
    68. // if (!url.hasQueryItem("access_token"))
    69. // return;
    70.  
    71. /* I commented previous part because most of you doesn't have VK accounts so you can't go
    72.   * to the next part of code */
    73.  
    74. access_token = url.queryItemValue("access_token");
    75. expires_in = url.queryItemValue("expires_in").toInt();
    76.  
    77. emit authorisationSucceed();
    78.  
    79. authorised = true;
    80. cookies = messagesPage->page()->networkAccessManager()->cookieJar()->cookiesForUrl(QUrl("http://vk.com"));
    81. messagesPage->deleteLater();
    82. writeCookies();
    83. }
    84.  
    85. void API_VK::readCookies() {
    86. QFile file("./resouces/vk.cookie");
    87. if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
    88. return;
    89. }
    90.  
    91. QTextStream in(&file);
    92. QByteArray name, value;
    93. while (!in.atEnd()) {
    94. in >> name >> value;
    95. cookies.append(QNetworkCookie(name, value));
    96. }
    97. }
    98.  
    99. void API_VK::writeCookies() {
    100. QFile file("./resouces/vk.cookie"); // note: this file exists
    101. if (!file.open(QIODevice::Truncate | QIODevice::Text)) { // 5. at this line i receive runtime errors
    102. return;
    103. }
    104.  
    105. QTextStream out(&file);
    106. for (QList<QNetworkCookie>::const_iterator i = cookies.begin(); i != cookies.end(); ++i) {
    107. out << (*i).name() << ' ' << (*i).value() << '\n';
    108. }
    109. }
    To copy to clipboard, switch view to plain text mode 

    printer.h

    Qt Code:
    1. #ifndef PRINTER_H
    2. #define PRINTER_H
    3.  
    4. #include <QObject>
    5. #include <QDebug>
    6.  
    7. struct Printer: public QObject {
    8. Q_OBJECT
    9.  
    10. public slots:
    11. void printOK() { qDebug() << "OK"; }
    12. void printFail() { qDebug() << "Fail"; }
    13. };
    14.  
    15. #endif // PRINTER_H
    To copy to clipboard, switch view to plain text mode 

    printer.cpp

    Qt Code:
    1. #include "printer.h"
    To copy to clipboard, switch view to plain text mode 

    Here's the full output with memory dump: http://pastebin.com/btVNe4nd

    At 5 QtCreator says that app received signal from OS (signal: SIGABRT) and decompiles

    Qt Code:
    1. Disassembler (__kernel_vsyscall)
    2.  
    3. 0x132414 <+0x0000> int $0x80
    4. 0x132416 <+0x0002> ret
    To copy to clipboard, switch view to plain text mode 

    And valgrind says:

    Qt Code:
    1. Analysis of memory <path>
    2. QMetaObject::connectSlotsByName: No matching signal for on_cancelButton_clicked()
    3. "sni-qt/23102" WARN 20:28:53.697 void StatusNotifierItemFactory::connectToSnw() Invalid interface to SNW_SERVICE
    4. ** Analysis finished **
    5. ** Unknown error **
    To copy to clipboard, switch view to plain text mode 

    Question on StackOwerflow: http://stackoverflow.com/questions/1...corruption-out

    So, why I receive they? I don't use malloc()/free(), you can see it.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,690
    Thanks
    13
    Thanked 1,599 Times in 1,527 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: runtime error: “*** glibc detected ***: double free or corruption (out)”

    Point 5. Line 101 of api_vk.cpp should specify QIODevice::WriteOnly

    The other Web Kit related warnings do not appear on my Linux build and do not seem related to the real problem.

    You are using malloc or a similar function, just not directly. You get double free because you create a QNetworkCookieJar instance as a member and pass a pointer to the QNetworkAccessManager (QNAM) underlying the web view. As the docs for QNetworkAccessManager::setCookieJar() tell you:
    Note: QNetworkAccessManager takes ownership of the cookieJar object.
    So, the cookie jar member variable is destroyed when it goes out of scope and the QNAM will also try to delete the cookie jar when the QNAM is destroyed by your deleteLater() call. Double-free == Boom!

    I am not sure why you have created a QNetworkCookieJar of your own anyway. QNAM has one by default and you are not passing a customised version in order to implement persistence (you do that outside the cookie jar object). To keep your implementation more-or-less intact make jar a local QNetworkCookieJar*, initialise it using QNetworkAccessManager::cookieJar(), and load the cookies into the existing instance.

    Alternatively, you could create a QNetworkCookieJar subclass that handles its own persistence. During initialisation you allocate a custom cookie jar class on the heap, set it on the QNAM, and let the QNAM handle deletion.
    Last edited by ChrisW67; 11th June 2012 at 02:31.

Similar Threads

  1. Replies: 2
    Last Post: 7th December 2010, 16:13
  2. Replies: 0
    Last Post: 29th September 2009, 02:16
  3. Replies: 3
    Last Post: 5th June 2009, 20:19
  4. *** glibc detected ***: free(): invalid pointer
    By codebehind in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2008, 23:45
  5. Error: **** glibc detected ****
    By Manohar in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2008, 06:32

Tags for this Thread

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.