Skip to content

Commit

Permalink
Print more trace when tmptable creation fails (#2517)
Browse files Browse the repository at this point in the history
Also abort immediately when tmp tbl is null instead of
crashing when we dereference its members.

Signed-off-by: Adi Zaimi <[email protected]>
  • Loading branch information
adizaimi committed Oct 3, 2020
1 parent 21c2677 commit 2581202
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 4 additions & 1 deletion bdb/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ as long as there was a successful move in the past
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <strings.h>
#include <assert.h>
Expand Down Expand Up @@ -6061,6 +6060,10 @@ static int bdb_cursor_move_int(bdb_cursor_impl_t *cur, int how, int *bdberr)
if (cur->vs_skip == NULL) {
assert(cur->vs_stab == NULL);
cur->vs_stab = bdb_temp_table_create(cur->state, bdberr);
if (!cur->vs_stab) {
logmsg(LOGMSG_FATAL, "bdb_temp_table_create returns NULL, bdberr=%d", *bdberr);
abort();
}
}
/* Otherwise truncate it. */
else {
Expand Down
21 changes: 13 additions & 8 deletions bdb/temptable.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,9 @@ static struct temp_table *bdb_temp_table_create_main(bdb_state_type *bdb_state,
parent = bdb_state;

tbl = calloc(1, sizeof(struct temp_table));
if (tbl == NULL) {
*bdberr = ENOMEM;
if (!tbl) {
logmsg(LOGMSG_ERROR, "%s:%d: Failed calloc", __func__, __LINE__);
*bdberr = BDBERR_MALLOC;
return NULL;
}

Expand Down Expand Up @@ -624,16 +625,20 @@ static struct temp_table *bdb_temp_table_create_main(bdb_state_type *bdb_state,
tbl->temp_hash_tbl = hash_init_user(hashfunc, hashcmpfunc, 0, 0);

tbl->elements = calloc(tbl->max_mem_entries, sizeof(arr_elem_t));
if (tbl->elements == NULL) {
bdb_temp_table_close(parent, tbl, bdberr);
if (tbl->sql) free(tbl->sql);
if (!tbl->elements) {
logmsg(LOGMSG_ERROR, "%s:%d: Failed calloc sz=%lld", __func__, __LINE__,
(long long int)tbl->max_mem_entries * sizeof(arr_elem_t));
int rc = bdb_temp_table_close(parent, tbl, bdberr);
if (rc) {
logmsg(LOGMSG_ERROR, "%s:%d: bdb_temp_table_close rc=%d, bdberr=%d",
__func__, __LINE__, rc, *bdberr);
}
*bdberr = BDBERR_MALLOC;
free(tbl->sql);
free(tbl);
tbl = NULL;
goto done;
}

done:

#ifdef _LINUX_SOURCE
if (gbl_debug_temptables) {
char *zBacktrace = get_stack_backtrace();
Expand Down

0 comments on commit 2581202

Please sign in to comment.