AtnNn / librethinkdbxx

RethinkDB driver for C++
Other
98 stars 31 forks source link

using order_by crashes the cursor's destructor #10

Open mflerackers opened 8 years ago

mflerackers commented 8 years ago

When using order_by, the query fails to return results, and the cursor's destructor crashes.

auto handle = std::async(std::launch::async, [](){
  try {
    std::unique_ptr<RethinkDB::Connection> conn = RethinkDB::connect("172.17.10.61", 28015);
    RethinkDB::Cursor cursor = RethinkDB::table("leaderboard").order_by("score").limit(2).run(*conn);
    for (auto score = cursor.begin(); score != cursor.end(); ++score) {
      printf("%s\n", RethinkDB::write_datum(*score).c_str());
    }
  } catch (RethinkDB::Error &err) {
    printf("%s\n", err.message.c_str());
  }
});
#7  0x0006f234 in std::__1::__vector_base<RethinkDB::Datum, std::__1::allocator<RethinkDB::Datum> >::~__vector_base() at /include/c++/v1/vector:472
#8  0x0006f164 in std::__1::vector<RethinkDB::Datum, std::__1::allocator<RethinkDB::Datum> >::~vector() at /include/c++/v1/iterator:1244
#9  0x0006efdc in std::__1::vector<RethinkDB::Datum, std::__1::allocator<RethinkDB::Datum> >::~vector() at /include/c++/v1/iterator:1244
#10 0x000a2f06 in RethinkDB::Cursor::~Cursor() at librethinkdbxx/src/cursor.cc:33

malloc: *\ error for object 0x14e6e6c0: pointer being freed was not allocated

I also tried

RethinkDB::Cursor cursor = RethinkDB::table("leaderboard").order_by("index", RethinkDB::desc("score")).limit(2).run(*conn);

Which also doesn't seem to work

AtnNn commented 8 years ago

I tried your query and got two rows from the database and no allocation errors.

Does this test work for you?

mflerackers commented 8 years ago

No, it crashes with the same error

AtnNn commented 8 years ago

I might be able to fix the issue if you can help me reproduce it.

Which commit are you compiling from? Have you patched the code in any way? What compiler are you using? How are you invoking the compiler and linker? What platform are you running the code on? What version of RethinkDB are you running it against?

mflerackers commented 8 years ago

I tried both the current master and work branches I only fixed some includes I use clang (Apple LLVM version 7.0.2 (clang-700.1.81)) with -std=c++14 The platform is iOS 9.3.1 RethinkDB is a stock rethinkdb 2.2.6~0trusty (GCC 4.8.2)