librethinkdbxx icon indicating copy to clipboard operation
librethinkdbxx copied to clipboard

using order_by crashes the cursor's destructor

Open mflerackers opened this issue 9 years ago • 4 comments

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

mflerackers avatar Mar 23 '16 04:03 mflerackers

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

Does this test work for you?

AtnNn avatar Mar 30 '16 15:03 AtnNn

No, it crashes with the same error

mflerackers avatar Mar 31 '16 08:03 mflerackers

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?

AtnNn avatar Mar 31 '16 12:03 AtnNn

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)

mflerackers avatar Apr 20 '16 09:04 mflerackers