objectbox / objectbox-c

C and C++ database for objects and structs
https://objectbox.io/
Apache License 2.0
194 stars 35 forks source link

coredump for double free to run example (win10 WSL) #32

Closed lymslive closed 11 months ago

lymslive commented 11 months ago

Describe the bug When I try the example c-cursor-no-gen, it is success to insert a new task, but print a coredump error in the end.

Basic info (please complete the following information):

To Reproduce

gdb information as following:

tanshuil@B013741:~/github/lymslive/lyObjectBox/build/_deps/objectbox-build/examples/c-cursor-no-gen$ gdb ./objectbox-c-examples-tasks
gdb: /usr/local/lib/libuuid.so.1: no version information available (required by /lib/x86_64-linux-gnu/libbabeltrace-ctf.so.1)
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./objectbox-c-examples-tasks...
(No debugging symbols found in ./objectbox-c-examples-tasks)
(gdb) r buy more milk
Starting program: /home/tanshuil/github/lymslive/lyObjectBox/build/_deps/objectbox-build/examples/c-cursor-no-gen/objectbox-c-examples-tasks buy more milk
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Using libobjectbox version 0.18.0, core version: 3.4.0-2022-10-31 (tree)
New task: 2 - buy more milk
free(): double free detected in tcache 2

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007fffff462859 in __GI_abort () at abort.c:79
#2  0x00007fffff4cd29e in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7fffff5f7298 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
#3  0x00007fffff4d532c in malloc_printerr (str=str@entry=0x7fffff5f95d0 "free(): double free detected in tcache 2") at malloc.c:5347
#4  0x00007fffff4d6f9d in _int_free (av=0x7fffff62cb80 <main_arena>, p=0x8029a50, have_lock=0) at malloc.c:4201
#5  0x00007fffff6e6627 in obx_txn_close () from /home/tanshuil/github/lymslive/lyObjectBox/build/_deps/objectbox-download-src/lib/libobjectbox.so
#6  0x0000000008005b5c in do_action_new ()
#7  0x00000000080057f9 in main ()
(gdb)
lymslive commented 11 months ago

By the way, there is no such problem in the other two similar examples: examples/c-gen nor examples/cpp-gen

greenrobot commented 11 months ago

Thanks for reporting, this is fixed internally and will be pushed with the next release.

To fix it locally, you can use this updated clean_up code:

if (txn) {
    if (!obx_last_error_code()) {
        obx_txn_success(txn);
    } else {
        obx_txn_close(txn);
    }
}

instead of

if (txn && !obx_last_error_code()) {
    obx_txn_success(txn);
}

if (txn) {
    obx_txn_close(txn);
}