diff --git a/src/future.cpp b/src/future.cpp index 331fb918d..70f63773c 100644 --- a/src/future.cpp +++ b/src/future.cpp @@ -62,10 +62,9 @@ const CassResult* cass_future_get_result(CassFuture* future) { if (result) { result->decode_first_row(); + result->inc_ref(); } - result->inc_ref(); - return CassResult::to(result.get()); } @@ -82,7 +81,7 @@ const CassPrepared* cass_future_get_prepared(CassFuture* future) { if (result && result->kind() == CASS_RESULT_KIND_PREPARED) { cass::Prepared* prepared = new cass::Prepared(result, response_future->statement, response_future->schema_metadata); - prepared->inc_ref(); + if (prepared) prepared->inc_ref(); return CassPrepared::to(prepared); } return NULL; @@ -98,7 +97,7 @@ const CassErrorResult* cass_future_get_error_result(CassFuture* future) { if (!response_future->is_error()) return NULL; cass::SharedRefPtr error_result(response_future->response()); - error_result->inc_ref(); + if (error_result) error_result->inc_ref(); return CassErrorResult::to(error_result.get()); } @@ -145,17 +144,20 @@ CassError cass_future_custom_payload_item(CassFuture* future, } cass::SharedRefPtr response( static_cast(future->from())->response()); - const cass::Response::CustomPayloadVec& custom_payload - = response->custom_payload(); - if (index >= custom_payload.size()) { - return CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS; + if (response) { + const cass::Response::CustomPayloadVec& custom_payload = + response->custom_payload(); + if (index >= custom_payload.size()) { + return CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS; + } + const cass::Response::CustomPayloadItem& item = custom_payload[index]; + *name = item.name.data(); + *name_length = item.name.size(); + *value = reinterpret_cast(item.value.data()); + *value_size = item.value.size(); + return CASS_OK; } - const cass::Response::CustomPayloadItem& item = custom_payload[index]; - *name = item.name.data(); - *name_length = item.name.size(); - *value = reinterpret_cast(item.value.data()); - *value_size = item.value.size(); - return CASS_OK; + return CASS_ERROR_LIB_INTERNAL_ERROR; } } // extern "C"