2017-08-08 97 views
0

反序列化正在工作,問題在於內存泄漏。 我已經嘗試刪除's'指針,但有'Targeting failure',我無法刪除指針。使用boost :: archive :: binary_iarchive的內存泄漏

//Statment MySql 
sql::Statement *_stmt = this->con->createStatement(); 
sql::ResultSet *_result = _stmt->executeQuery("SELECT * FROM matches ORDER BY `match_seq_num` ASC LIMIT 1250"); 

while(_result->next()){ 
    std::istream *s = _result->getBlob("match_object"); 
    boost::archive::binary_iarchive ia(*s); 
    Match _match; 
    ia >> _match; 
    delete s; 
} 
delete _result; 
delete _stmt; 

的問題是使用boost::archive::binary_iarchive ia(*s);反序列化從MySQL傳來的信息後刪除的「指針。

+0

我從來沒有見過這樣的使用iarchive。該錯誤可能在您的不透明函數getBlob()中。 –

回答

1

當然你需要刪除。

如果出現問題,您應該解決該問題。你的更新指向一個可能的罪魁禍首:輸入檔案需要參考istream,仍然可以在析構函數中訪問它(事實上我認爲它可能)。因此,請確保它在破壞所需資源之前已經消失:

//Statment MySql 
sql::Statement *_stmt = this->con->createStatement(); 
sql::ResultSet *_result = _stmt->executeQuery("SELECT * FROM matches ORDER BY `match_seq_num` ASC LIMIT 1250"); 

while(_result->next()){ 
    Match _match; 
    { 
     std::istream *s = _result->getBlob("match_object"); 
     { 
      boost::archive::binary_iarchive ia(*s); 
      ia >> _match; 
     } 
     delete s; 
    } 
} 
delete _result; 
delete _stmt; 
+0

哦,我錯過了關於「瞄準失敗」的部分。告訴我們更多關於給你'_result'的圖書館。它應該有關於如何處理資源所有權/生命週期的文檔。 – sehe

+0

我對這個問題做了一些更改,使問題更加明顯。從我所看到的,在使用'boost :: archive :: binary_iarchive ia(* s);' –

+0

後,某些東西繼續使用's'指針我已經更新了相應的答案。 – sehe