2016-11-20 7 views
0

実行時にループで2回、Bad_Accessがクラッシュし、クエリを要求してPrepareStatementを呼び出しました。C++ MySQLコネクタPrepareStatement Bad_Access

私はすべてのResultSetメモリをチェックし、それをすべてリリースしましたが、何も考えられません。 この問題を解決する方法はありますか?

CallStack

メンバ値についての説明。

PrepareStatement* pstmt; 

ResultSet* res; 

と完全なコード

bool laskdjlaskdj12::RaspBerry::grup_pw_chk(const Json::Value j){ 

//check the id and group is valid 
try{ 

    string group = j["Group"].asString(); 
    const char* id = j["id"].asCString(); 
    string grp; 
    string pub; 
    BIO* tmp;       //BIO structor to change the RSA* structor 

    if(group == "NULL"){ 
     group = ""; 
    } 
    //request the Client is existence 
    pstmt = con->prepareStatement("SELECT * FROM `raspberry_cli` WHERE `Cli_id` = (?) AND `Cli_Group` = (?)"); 
    pstmt->setString(1, id); 
    pstmt->setString(2, group); 

    res = pstmt->executeQuery(); 

    //if query reply is NULL 
    if(res->next() == false){ 
     std::cout<<"[INFO] : There is no query about raspberry_cli"<<std::endl; 
     return false; 
    } 
    //if query Reply 
    grp = res->getString("Cli_Group"); 
    pub = res->getString("Cli_Pub"); 
    //if There is no group in Raspberry_pi 
    if(ras.grp.compare(grp) == false){ 
     //sql의 버퍼 flush 
     this->SQL_Flush(); 
     return false; 
    } 
    // if the group is equal 
    else{ 
     //save the client information 
     acc_cli.S_id = id; 
     acc_cli.S_Group = grp; 

     //save the client public_key 
     tmp = BIO_new_mem_buf(pub.c_str(), -1); 
     acc_cli.Pub_key = PEM_read_bio_RSA_PUBKEY(tmp, NULL, 0, NULL); 
     //if public key is not wright in section 
     if(acc_cli.Pub_key == NULL){ 
      return false; 
     } 
     delete[] tmp; 
     //flush SQL_flush = delete ResultSet 
     this->SQL_Flush(); 
     return true; 
    } 
}catch(sql::SQLException& e){ 
    std::cout << "# ERR: SQLException in " << __FILE__; 
    std::cout << "(" << __FUNCTION__ << ") on line "<< __LINE__ << std::endl; 
    std::cout << "# ERR: " << e.what(); 
    std::cout << " (MySQL error code: " << e.getErrorCode(); 
    std::cout << ", SQLState: " << e.getSQLState() << ")" << std::endl; 
    return false; 
} 

DETALのStackTraceは、このセクションの

pstmt = con->prepareStatement("SELECT * FROM `raspberry_cli` WHERE `Cli_id` = (?) AND `Cli_Group` = (?)"); 
pstmt->setString(1, id); 
pstmt->setString(2, group); 

res = pstmt->executeQuery(); 

[delete pstmt;]  //===================> This part is missing 

答えを探すこの

* thread #1: tid = 0x2778b, 0x00000001000e29c3 RaspBerry`list_add(root=0x0000000100903e38, element=0x00000001009043e8) + 19 at list.c:33, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT) 
frame #0: 0x00000001000e29c3 RaspBerry`list_add(root=0x0000000100903e38, element=0x00000001009043e8) + 19 at list.c:33 [opt] 
frame #1: 0x00000001000de27f RaspBerry`mysql_stmt_init(mysql=0x0000000102802220) + 143 at libmysql.c:1568 [opt] 
frame #2: 0x0000000100168f41 RaspBerry`sql::mysql::NativeAPI::MySQL_NativeConnectionWrapper::stmt_init(this=0x0000000100a00580) + 33 at mysql_native_connection_wrapper.cpp:421 [opt] 
frame #3: 0x000000010011c415 RaspBerry`sql::mysql::MySQL_Connection::prepareStatement(this=0x0000000100a00550, sql=0x00007fff5fbfe138) + 53 at mysql_connection.cpp:1137 [opt] 
* frame #4: 0x0000000100073071 RaspBerry`laskdjlaskdj12::RaspBerry::grup_pw_chk(this=0x00007fff5fbfeba0, j=const Json::Value @ 0x00007fff5fbfea30) + 881 at RaspBerry.cpp:438 
frame #5: 0x000000010007c222 RaspBerry`main(argc=1, argv=0x00007fff5fbff7f8) + 3474 at main.cpp:81 
frame #6: 0x00007fffced8b255 libdyld.dylib`start + 1 
frame #7: 0x00007fffced8b255 libdyld.dylib`start + 1 
+0

エラーは「Raspberry_Piは最適化されてコンパイルされました。ステッピングが異常に動作する可能性がありますが、変数が使用できない可能性があります。 –

+0

stacktraceをテキストとして投稿してください。 – Danh

+0

@marc_sありがとう –

答えて

1

である私は(てpstmtを削除しませんでしたsql :: preparestatement *) SQLはそのmallocエラーを送信しています。

したがって、メモリの割り当てには注意してください。

関連する問題