Skip to content

Commit

Permalink
Cleanup and remove a bad and unecessary instance of memcopying from i…
Browse files Browse the repository at this point in the history
…nvalid memory (bloomberg#1313)

Cleanup and remove a bad and unecessary instance of memcopying from invalid memory
  • Loading branch information
adizaimi authored Dec 19, 2018
1 parent 312c2c0 commit 43ea6ab
Showing 1 changed file with 47 additions and 55 deletions.
102 changes: 47 additions & 55 deletions bdb/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1961,72 +1961,64 @@ static int bdb_fetch_int_ll(
}

/* if we were told to retrieve the record number, do it now */
if (recnum) {
switch (direction) {
case FETCH_INT_CUR_BY_RECNUM:
break;

default:
*recnum = -1;

if (ixrecnum) {
if (ixfound)
memcpy(tmp_key, ixfound, ixlen_full);
if (recnum && direction != FETCH_INT_CUR_BY_RECNUM) {
*recnum = -1;

memset(&dbt_key, 0, sizeof(dbt_key));
memset(&dbt_data, 0, sizeof(dbt_data));

dbt_key.flags = DB_DBT_USERMEM;
dbt_key.data = tmp_key;
dbt_key.size = ixlen_full;
dbt_key.ulen = sizeof(tmp_key);
if (ixrecnum) {
if (ixfound)
memcpy(tmp_key, ixfound, ixlen_full);

dbt_data.flags = DB_DBT_USERMEM;
dbt_data.data = tmp_data;
dbt_data.size = sizeof(tmp_data);
dbt_data.ulen = sizeof(tmp_data);
memset(&dbt_key, 0, sizeof(dbt_key));
memset(&dbt_data, 0, sizeof(dbt_data));

if (keycontainsgenid) {
masked_genid = get_search_genid(bdb_state, foundgenid);
memcpy(tmp_key + ixlen_full, &masked_genid,
sizeof(unsigned long long));
dbt_key.size += sizeof(unsigned long long);
}
dbt_key.flags = DB_DBT_USERMEM;
dbt_key.data = tmp_key;
dbt_key.size = ixlen_full;
dbt_key.ulen = sizeof(tmp_key);

rc = fetch_cget(bdb_state, ixnum, dbcp, &dbt_key, &dbt_data,
DB_SET);
dbt_data.flags = DB_DBT_USERMEM;
dbt_data.data = tmp_data;
dbt_data.size = sizeof(tmp_data);
dbt_data.ulen = sizeof(tmp_data);

if (rc != 0) {
/* return DEADLOCK */
if (CURSOR_SER_ENABLED(bdb_state) && cur_ser &&
!lookahead) {
rc = dbcp->c_close_ser(dbcp, &cur_ser->dbcs);
cur_ser->is_valid = !rc;
} else
rc = dbcp->c_close(dbcp);
*bdberr = BDBERR_DEADLOCK;
if (keycontainsgenid) {
masked_genid = get_search_genid(bdb_state, foundgenid);
memcpy(tmp_key + ixlen_full, &masked_genid,
sizeof(unsigned long long));
dbt_key.size += sizeof(unsigned long long);
}

outrc = -1;
*recnum = -1;
return outrc;
}
rc =
fetch_cget(bdb_state, ixnum, dbcp, &dbt_key, &dbt_data, DB_SET);

if (rc != 0) {
/* return DEADLOCK */
if (CURSOR_SER_ENABLED(bdb_state) && cur_ser && !lookahead) {
rc = dbcp->c_close_ser(dbcp, &cur_ser->dbcs);
cur_ser->is_valid = !rc;
} else
rc = dbcp->c_close(dbcp);
*bdberr = BDBERR_DEADLOCK;

memset(&dbt_data, 0, sizeof(dbt_data));
dbt_data.data = recnum;
dbt_data.ulen = sizeof(int);
dbt_data.flags = DB_DBT_USERMEM;
outrc = -1;
*recnum = -1;
return outrc;
}

rc = fetch_cget(bdb_state, ixnum, dbcp, &dbt_key, &dbt_data,
DB_GET_RECNO);
memset(&dbt_data, 0, sizeof(dbt_data));
dbt_data.data = recnum;
dbt_data.ulen = sizeof(int);
dbt_data.flags = DB_DBT_USERMEM;

if ((rc == DB_REP_HANDLE_DEAD) || (rc == DB_LOCK_DEADLOCK)) {
*bdberr = BDBERR_DEADLOCK;
}
rc = fetch_cget(bdb_state, ixnum, dbcp, &dbt_key, &dbt_data,
DB_GET_RECNO);

if (rc != 0)
*recnum = -1;
if ((rc == DB_REP_HANDLE_DEAD) || (rc == DB_LOCK_DEADLOCK)) {
*bdberr = BDBERR_DEADLOCK;
}
break;

if (rc != 0)
*recnum = -1;
}
}
/********************************************************************/
Expand Down

0 comments on commit 43ea6ab

Please sign in to comment.