Valgrind reports multiple errors around the path via ha_oqgraph::close() Invalid read of size 4 ==28028== at 0x272EE579: oqgraph3::cursor_ptr::~cursor_ptr() (oqgraph_thunk.h:132) ==28028== by 0x272EE77A: open_query::edges_cursor::~edges_cursor() (oqgraph_thunk.h:68) ==28028== by 0x272EA0E6: open_query::oqgraph::release_cursor() (graphcore.cc:706) ==28028== by 0x272E7243: ha_oqgraph::external_lock(THD*, int) (ha_oqgraph.cc:1129) ==28028== by 0x6C4A11: handler::ha_external_lock(THD*, int) (handler.cc:5740) ==28028== by 0x7728A0: unlock_external(THD*, TABLE**, unsigned int) (lock.cc:671) ==28028== by 0x772A27: mysql_unlock_tables(THD*, st_mysql_lock*, bool) (lock.cc:382) ==28028== by 0x5519F7: close_thread_tables(THD*) (sql_base.cc:960) ==28028== by 0x5894E1: mysql_execute_command(THD*) (sql_parse.cc:5023) ==28028== by 0x58F83C: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6264) ==28028== by 0x590D45: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1277) ==28028== by 0x6435F3: do_handle_one_connection(THD*) (sql_connect.cc:1379) ==28028== Address 0x1c1f6370 is 0 bytes inside a block of size 80 free'd ==28028== at 0x4C23E0F: operator delete(void*) (vg_replace_malloc.c:387) ==28028== by 0x272EA0CC: open_query::oqgraph::release_cursor() (graphcore.cc:703) ==28028== by 0x272E7243: ha_oqgraph::external_lock(THD*, int) (ha_oqgraph.cc:1129) ==28028== by 0x6C4A11: handler::ha_external_lock(THD*, int) (handler.cc:5740) ==28028== by 0x7728A0: unlock_external(THD*, TABLE**, unsigned int) (lock.cc:671) ==28028== by 0x772A27: mysql_unlock_tables(THD*, st_mysql_lock*, bool) (lock.cc:382) ==28028== by 0x5519F7: close_thread_tables(THD*) (sql_base.cc:960) ==28028== by 0x5894E1: mysql_execute_command(THD*) (sql_parse.cc:5023) ==28028== by 0x58F83C: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6264) ==28028== by 0x590D45: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1277) ==28028== by 0x6435F3: do_handle_one_connection(THD*) (sql_connect.cc:1379) ==28028== by 0x64367F: handle_one_connection (sql_connect.cc:1293) ==28028== ==28028== Invalid write of size 4 ==28028== at 0x272EE580: oqgraph3::cursor_ptr::~cursor_ptr() (oqgraph_thunk.h:132) ==28028== by 0x272EE77A: open_query::edges_cursor::~edges_cursor() (oqgraph_thunk.h:68) ==28028== by 0x272EA0E6: open_query::oqgraph::release_cursor() (graphcore.cc:706) ==28028== by 0x272E7243: ha_oqgraph::external_lock(THD*, int) (ha_oqgraph.cc:1129) ==28028== by 0x6C4A11: handler::ha_external_lock(THD*, int) (handler.cc:5740) ==28028== by 0x7728A0: unlock_external(THD*, TABLE**, unsigned int) (lock.cc:671) ==28028== by 0x772A27: mysql_unlock_tables(THD*, st_mysql_lock*, bool) (lock.cc:382) ==28028== by 0x5519F7: close_thread_tables(THD*) (sql_base.cc:960) ==28028== by 0x5894E1: mysql_execute_command(THD*) (sql_parse.cc:5023) ==28028== by 0x58F83C: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6264) ==28028== by 0x590D45: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1277) ==28028== by 0x6435F3: do_handle_one_connection(THD*) (sql_connect.cc:1379) ==28028== Address 0x1c1f6370 is 0 bytes inside a block of size 80 free'd ==28028== at 0x4C23E0F: operator delete(void*) (vg_replace_malloc.c:387) ==28028== by 0x272EA0CC: open_query::oqgraph::release_cursor() (graphcore.cc:703) ==28028== by 0x272E7243: ha_oqgraph::external_lock(THD*, int) (ha_oqgraph.cc:1129) ==28028== by 0x6C4A11: handler::ha_external_lock(THD*, int) (handler.cc:5740) ==28028== by 0x7728A0: unlock_external(THD*, TABLE**, unsigned int) (lock.cc:671) ==28028== by 0x772A27: mysql_unlock_tables(THD*, st_mysql_lock*, bool) (lock.cc:382) ==28028== by 0x5519F7: close_thread_tables(THD*) (sql_base.cc:960) ==28028== by 0x5894E1: mysql_execute_command(THD*) (sql_parse.cc:5023) ==28028== by 0x58F83C: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6264) ==28028== by 0x590D45: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1277) ==28028== by 0x6435F3: do_handle_one_connection(THD*) (sql_connect.cc:1379) ==28028== by 0x64367F: handle_one_connection (sql_connect.cc:1293)