Invalid memory access error



  • Hi,

    I'm using qt-jambi to develop an app that goes through a list of URLs, loads them in a QtWebView page and then parses them for links. To force the app to be synchronous (i.e. completely finish with one page before moving onto the next), we exec a QEventLoop. In the event that a page takes too long to load, we have a timer that fires 30 seconds and forces the app to move on. However, after some random number of URLs, the app always segfaults and points to a different part of libQtWebkit. For example:

    C [libQtWebKit.so.4+0x3ff181] WTF::TCMalloc_Central_FreeList::FetchFromSpans()+0x31

    C [libQtWebKit.so.4+0x87d239] WebCore::QNetworkReplyHandler::sendResponseIfNeeded()+0xa09

    and so forth.

    What's interesting is if, in the loadFinished slot, we comment out the code that parses the page for links, there is never a segfault. Any ideas would be appreciated. A slimmed down version of the code is below or at http://pastiebin.com/?page=p&id=4f5bb860922e6

    Thanks!

    -Arvind

    @public class PostProcess extends QMainWindow {
    private QEventLoop mLoop;
    private QWebView mBrowser;
    private QTimer mTimer;

    private String[] mPageData;
    private int mPageIndex;
    
    public PostProcess() {
            this(null);
        }
    
    public PostProcess(QWidget parent) {
        super(parent);
    
        mLoop = new QEventLoop();
    
        mBrowser = new QWebView();
        setCentralWidget(mBrowser);
    
        mTimer = new QTimer();
        mTimer.setInterval(1000 * 30);
        mTimer.setSingleShot(true);
        mTimer.timeout.connect(this, "pageTimedOut()");
    }
    
    public static void main(String[] args) throws InterruptedException, IOException {          
        QApplication.initialize(args);
        
        PostProcess pp = new PostProcess();
        
        pp.run();
        
        QApplication.exit();
    }
    
    private void postProcess() {
        while (mPageIndex < mPageData.length) {
            String uri    = mPageData[mPageIndex];
    
            QNetworkAccessManager manager = new PostProcessNetworkAccessManager(pageId);
            mBrowser.page().setNetworkAccessManager(manager);
            mBrowser.page().settings().clearMemoryCaches();
            mBrowser.loadFinished.connect(this, "loadFinished(Boolean)");
            mBrowser.loadProgress.connect(this, "loadProgress(int)");
            
            QNetworkRequest req = new QNetworkRequest(new QUrl("http://" + uri));
            req.setRawHeader(FROM_CACHE, new QByteArray("1"));
            req.setRawHeader(PAGE_ID, new QByteArray(pageId));
            
            mTimer.start();
            
            mBrowser.load(req);
            
            mLoop.exec&#40;&#41;;   
            
            mPageIndex++;
        }
    }
    
    private void loadFinished(Boolean ok) { 
        debug("LOAD FINISHED: " + mBrowser.url() + " " + ok);
        mTimer.stop();
    
        mBrowser.loadFinished.disconnect();
        mBrowser.loadProgress.disconnect();
        mBrowser.stop();
    
        if(ok == true) {
            QWebElementCollection anchors = page.mainFrame().findAllElements("a");
         for(QWebElement anchor: anchors.toList())
             nextURIs.add(anchor.attribute("href"));
        }
    
        mLoop.exit();
    }
    
    private void loadProgress(int i) {
        System.err.print(i + "...");
    }
    
    private void pageTimedOut() {
        debug("TIMED OUT PAGE LOAD " + mBrowser.url());
        mBrowser.loadFinished.disconnect();
        mBrowser.loadProgress.disconnect();
    
        mBrowser.load(new QUrl("about:blank"));
        mLoop.exit();
    }@

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.