diff --git a/cpp/src/arrow/array.cc b/cpp/src/arrow/array.cc index 92e8d0f0fa8..12922ae7b0a 100644 --- a/cpp/src/arrow/array.cc +++ b/cpp/src/arrow/array.cc @@ -224,6 +224,8 @@ Status ListArray::FromArrays(const Array& offsets, const Array& values, void ListArray::SetData(const std::shared_ptr& data) { this->Array::SetData(data); + DCHECK_EQ(data->buffers.size(), 2); + auto value_offsets = data->buffers[1]; raw_value_offsets_ = value_offsets == nullptr ? nullptr @@ -246,6 +248,7 @@ BinaryArray::BinaryArray(const std::shared_ptr& data) { } void BinaryArray::SetData(const std::shared_ptr& data) { + DCHECK_EQ(data->buffers.size(), 3); auto value_offsets = data->buffers[1]; auto value_data = data->buffers[2]; this->Array::SetData(data); @@ -342,6 +345,7 @@ std::shared_ptr StructArray::field(int i) const { if (!boxed_fields_[i]) { DCHECK(MakeArray(data_->child_data[i], &boxed_fields_[i]).ok()); } + DCHECK(boxed_fields_[i]); return boxed_fields_[i]; } @@ -351,6 +355,8 @@ std::shared_ptr StructArray::field(int i) const { void UnionArray::SetData(const std::shared_ptr& data) { this->Array::SetData(data); + DCHECK_EQ(data->buffers.size(), 3); + auto type_ids = data_->buffers[1]; auto value_offsets = data_->buffers[2]; raw_type_ids_ = @@ -385,6 +391,7 @@ std::shared_ptr UnionArray::child(int i) const { if (!boxed_fields_[i]) { DCHECK(MakeArray(data_->child_data[i], &boxed_fields_[i]).ok()); } + DCHECK(boxed_fields_[i]); return boxed_fields_[i]; } @@ -594,10 +601,11 @@ class ArrayDataWrapper { } // namespace internal -// Remove enclosing namespace after 0.7.0 Status MakeArray(const std::shared_ptr& data, std::shared_ptr* out) { internal::ArrayDataWrapper wrapper_visitor(data, out); - return VisitTypeInline(*data->type, &wrapper_visitor); + RETURN_NOT_OK(VisitTypeInline(*data->type, &wrapper_visitor)); + DCHECK(out); + return Status::OK(); } #ifndef ARROW_NO_DEPRECATED_API diff --git a/cpp/src/arrow/array.h b/cpp/src/arrow/array.h index ee29d950682..4ad60eb77f4 100644 --- a/cpp/src/arrow/array.h +++ b/cpp/src/arrow/array.h @@ -84,7 +84,7 @@ struct Decimal; /// input array and replace them with newly-allocated data, changing the output /// data type as well. struct ARROW_EXPORT ArrayData { - ArrayData() {} + ArrayData() : length(0) {} ArrayData(const std::shared_ptr& type, int64_t length, int64_t null_count = kUnknownNullCount, int64_t offset = 0) diff --git a/cpp/src/arrow/buffer.h b/cpp/src/arrow/buffer.h index dbd93763638..5f61ade956b 100644 --- a/cpp/src/arrow/buffer.h +++ b/cpp/src/arrow/buffer.h @@ -201,7 +201,7 @@ class ARROW_EXPORT BufferBuilder { if (elements == 0) { return Status::OK(); } - if (capacity_ == 0) { + if (buffer_ == nullptr) { buffer_ = std::make_shared(pool_); } int64_t old_capacity = capacity_; diff --git a/cpp/src/arrow/io/hdfs-internal.cc b/cpp/src/arrow/io/hdfs-internal.cc index e6d0487a9db..9cd1c5052fe 100644 --- a/cpp/src/arrow/io/hdfs-internal.cc +++ b/cpp/src/arrow/io/hdfs-internal.cc @@ -44,6 +44,7 @@ #include // NOLINT #include "arrow/status.h" +#include "arrow/util/logging.h" namespace fs = boost::filesystem; @@ -346,6 +347,7 @@ bool LibHdfsShim::HasPread() { tSize LibHdfsShim::Pread(hdfsFS fs, hdfsFile file, tOffset position, void* buffer, tSize length) { GET_SYMBOL(this, hdfsPread); + DCHECK(this->hdfsPread); return this->hdfsPread(fs, file, position, buffer, length); } diff --git a/cpp/src/arrow/ipc/message.cc b/cpp/src/arrow/ipc/message.cc index 082c92556b7..0c587ab7b23 100644 --- a/cpp/src/arrow/ipc/message.cc +++ b/cpp/src/arrow/ipc/message.cc @@ -29,6 +29,7 @@ #include "arrow/ipc/Schema_generated.h" #include "arrow/ipc/metadata-internal.h" #include "arrow/status.h" +#include "arrow/util/logging.h" namespace arrow { namespace ipc { @@ -194,9 +195,18 @@ std::string FormatMessageType(Message::Type type) { Status ReadMessage(int64_t offset, int32_t metadata_length, io::RandomAccessFile* file, std::unique_ptr* message) { + DCHECK_GT(static_cast(metadata_length), sizeof(int32_t)); + std::shared_ptr buffer; RETURN_NOT_OK(file->ReadAt(offset, metadata_length, &buffer)); + if (buffer->size() < metadata_length) { + std::stringstream ss; + ss << "Expected to read " << metadata_length << " metadata bytes but got " + << buffer->size(); + return Status::Invalid(ss.str()); + } + int32_t flatbuffer_size = *reinterpret_cast(buffer->data()); if (flatbuffer_size + static_cast(sizeof(int32_t)) > metadata_length) { diff --git a/cpp/src/arrow/ipc/reader.cc b/cpp/src/arrow/ipc/reader.cc index 09def6ea6ed..e6ba50e742f 100644 --- a/cpp/src/arrow/ipc/reader.cc +++ b/cpp/src/arrow/ipc/reader.cc @@ -349,7 +349,6 @@ Status ReadDictionary(const Buffer& metadata, const DictionaryTypeMap& dictionar reinterpret_cast(dictionary_batch->data()); RETURN_NOT_OK( ReadRecordBatch(batch_meta, dummy_schema, kMaxNestingDepth, file, &batch)); - if (batch->num_columns() != 1) { return Status::Invalid("Dictionary record batch must only contain one field"); } @@ -526,6 +525,13 @@ class RecordBatchFileReader::RecordBatchFileReaderImpl { int file_end_size = static_cast(magic_size + sizeof(int32_t)); RETURN_NOT_OK(file_->ReadAt(footer_offset_ - file_end_size, file_end_size, &buffer)); + const int64_t expected_footer_size = magic_size + sizeof(int32_t); + if (buffer->size() < expected_footer_size) { + std::stringstream ss; + ss << "Unable to read " << expected_footer_size << "from end of file"; + return Status::Invalid(ss.str()); + } + if (memcmp(buffer->data() + sizeof(int32_t), kArrowMagicBytes, magic_size)) { return Status::Invalid("Not an Arrow file"); } diff --git a/cpp/src/arrow/memory_pool.cc b/cpp/src/arrow/memory_pool.cc index d86fb08be89..851065b5211 100644 --- a/cpp/src/arrow/memory_pool.cc +++ b/cpp/src/arrow/memory_pool.cc @@ -112,8 +112,9 @@ Status DefaultMemoryPool::Reallocate(int64_t old_size, int64_t new_size, uint8_t // Note: We cannot use realloc() here as it doesn't guarantee alignment. // Allocate new chunk - uint8_t* out; + uint8_t* out = nullptr; RETURN_NOT_OK(AllocateAligned(new_size, &out)); + DCHECK(out); // Copy contents and release old memory chunk memcpy(out, *ptr, static_cast(std::min(new_size, old_size))); #ifdef _MSC_VER diff --git a/cpp/src/arrow/python/CMakeLists.txt b/cpp/src/arrow/python/CMakeLists.txt index 7938d8473b6..af53a1631f7 100644 --- a/cpp/src/arrow/python/CMakeLists.txt +++ b/cpp/src/arrow/python/CMakeLists.txt @@ -40,7 +40,7 @@ endif() set(ARROW_PYTHON_MIN_TEST_LIBS arrow_python_test_main - arrow_python_shared + arrow_python_static arrow_shared) set(ARROW_PYTHON_TEST_LINK_LIBS ${ARROW_PYTHON_MIN_TEST_LIBS}) diff --git a/cpp/src/arrow/python/arrow_to_pandas.cc b/cpp/src/arrow/python/arrow_to_pandas.cc index be738e7f922..88b594cac94 100644 --- a/cpp/src/arrow/python/arrow_to_pandas.cc +++ b/cpp/src/arrow/python/arrow_to_pandas.cc @@ -615,8 +615,8 @@ static Status ConvertDecimals(PandasOptions options, const ChunkedArray& data, PyAcquireGIL lock; OwnedRef decimal_ref; OwnedRef Decimal_ref; - RETURN_NOT_OK(ImportModule("decimal", &decimal_ref)); - RETURN_NOT_OK(ImportFromModule(decimal_ref, "Decimal", &Decimal_ref)); + RETURN_NOT_OK(internal::ImportModule("decimal", &decimal_ref)); + RETURN_NOT_OK(internal::ImportFromModule(decimal_ref, "Decimal", &Decimal_ref)); PyObject* Decimal = Decimal_ref.obj(); for (int c = 0; c < data.num_chunks(); c++) { @@ -633,7 +633,8 @@ static Status ConvertDecimals(PandasOptions options, const ChunkedArray& data, const uint8_t* raw_value = arr->GetValue(i); std::string decimal_string; RETURN_NOT_OK(RawDecimalToString(raw_value, precision, scale, &decimal_string)); - RETURN_NOT_OK(DecimalFromString(Decimal, decimal_string, out_values++)); + *out_values++ = internal::DecimalFromString(Decimal, decimal_string); + RETURN_IF_PYERROR(); } } } diff --git a/cpp/src/arrow/python/arrow_to_python.cc b/cpp/src/arrow/python/arrow_to_python.cc index a281fe3c629..b4f4a41f440 100644 --- a/cpp/src/arrow/python/arrow_to_python.cc +++ b/cpp/src/arrow/python/arrow_to_python.cc @@ -59,6 +59,10 @@ Status DeserializeDict(PyObject* context, const Array& array, int64_t start_idx, const auto& data = static_cast(array); ScopedRef keys, vals; ScopedRef result(PyDict_New()); + RETURN_IF_PYERROR(); + + DCHECK_EQ(2, data.num_fields()); + RETURN_NOT_OK(DeserializeList(context, *data.field(0), start_idx, stop_idx, base, tensors, keys.ref())); RETURN_NOT_OK(DeserializeList(context, *data.field(1), start_idx, stop_idx, base, diff --git a/cpp/src/arrow/python/builtin_convert.cc b/cpp/src/arrow/python/builtin_convert.cc index f9d7361e004..69a19e7a367 100644 --- a/cpp/src/arrow/python/builtin_convert.cc +++ b/cpp/src/arrow/python/builtin_convert.cc @@ -656,7 +656,7 @@ class DecimalConverter inline Status AppendItem(const OwnedRef& item) { /// TODO(phillipc): Check for nan? std::string string; - RETURN_NOT_OK(PythonDecimalToString(item.obj(), &string)); + RETURN_NOT_OK(internal::PythonDecimalToString(item.obj(), &string)); Decimal128 value; RETURN_NOT_OK(Decimal128::FromString(string, &value)); diff --git a/cpp/src/arrow/python/helpers.cc b/cpp/src/arrow/python/helpers.cc index fb2fed7f0ca..ad6a7f125e0 100644 --- a/cpp/src/arrow/python/helpers.cc +++ b/cpp/src/arrow/python/helpers.cc @@ -55,6 +55,8 @@ std::shared_ptr GetPrimitiveType(Type::type type) { } } +namespace internal { + Status ImportModule(const std::string& module_name, OwnedRef* ref) { PyObject* module = PyImport_ImportModule(module_name.c_str()); RETURN_IF_PYERROR(); @@ -106,10 +108,9 @@ Status InferDecimalPrecisionAndScale(PyObject* python_decimal, int* precision, return Decimal128::FromString(c_string, nullptr, precision, scale); } -Status DecimalFromString(PyObject* decimal_constructor, const std::string& decimal_string, - PyObject** out) { +PyObject* DecimalFromString(PyObject* decimal_constructor, + const std::string& decimal_string) { DCHECK_NE(decimal_constructor, nullptr); - DCHECK_NE(out, nullptr); auto string_size = decimal_string.size(); DCHECK_GT(string_size, 0); @@ -117,11 +118,10 @@ Status DecimalFromString(PyObject* decimal_constructor, const std::string& decim auto string_bytes = decimal_string.c_str(); DCHECK_NE(string_bytes, nullptr); - *out = PyObject_CallFunction(decimal_constructor, const_cast("s#"), string_bytes, + return PyObject_CallFunction(decimal_constructor, const_cast("s#"), string_bytes, string_size); - RETURN_IF_PYERROR(); - return Status::OK(); } +} // namespace internal } // namespace py } // namespace arrow diff --git a/cpp/src/arrow/python/helpers.h b/cpp/src/arrow/python/helpers.h index 8b8c6673c8e..01ab91657d9 100644 --- a/cpp/src/arrow/python/helpers.h +++ b/cpp/src/arrow/python/helpers.h @@ -28,26 +28,28 @@ #include "arrow/util/visibility.h" namespace arrow { - namespace py { class OwnedRef; -ARROW_EXPORT std::shared_ptr GetPrimitiveType(Type::type type); +ARROW_EXPORT +std::shared_ptr GetPrimitiveType(Type::type type); + +namespace internal { -Status ARROW_EXPORT ImportModule(const std::string& module_name, OwnedRef* ref); -Status ARROW_EXPORT ImportFromModule(const OwnedRef& module, - const std::string& module_name, OwnedRef* ref); +Status ImportModule(const std::string& module_name, OwnedRef* ref); +Status ImportFromModule(const OwnedRef& module, const std::string& module_name, + OwnedRef* ref); -Status ARROW_EXPORT PythonDecimalToString(PyObject* python_decimal, std::string* out); +Status PythonDecimalToString(PyObject* python_decimal, std::string* out); -Status ARROW_EXPORT InferDecimalPrecisionAndScale(PyObject* python_decimal, - int* precision = nullptr, - int* scale = nullptr); +Status InferDecimalPrecisionAndScale(PyObject* python_decimal, int* precision = nullptr, + int* scale = nullptr); -Status ARROW_EXPORT DecimalFromString(PyObject* decimal_constructor, - const std::string& decimal_string, PyObject** out); +PyObject* DecimalFromString(PyObject* decimal_constructor, + const std::string& decimal_string); +} // namespace internal } // namespace py } // namespace arrow diff --git a/cpp/src/arrow/python/numpy_to_arrow.cc b/cpp/src/arrow/python/numpy_to_arrow.cc index 8845ee7838e..c0ce61cca55 100644 --- a/cpp/src/arrow/python/numpy_to_arrow.cc +++ b/cpp/src/arrow/python/numpy_to_arrow.cc @@ -652,8 +652,8 @@ Status NumPyConverter::ConvertDecimals() { // Import the decimal module and Decimal class OwnedRef decimal; OwnedRef Decimal; - RETURN_NOT_OK(ImportModule("decimal", &decimal)); - RETURN_NOT_OK(ImportFromModule(decimal, "Decimal", &Decimal)); + RETURN_NOT_OK(internal::ImportModule("decimal", &decimal)); + RETURN_NOT_OK(internal::ImportFromModule(decimal, "Decimal", &Decimal)); Ndarray1DIndexer objects(arr_); PyObject* object = objects[0]; @@ -661,7 +661,7 @@ Status NumPyConverter::ConvertDecimals() { int precision; int scale; - RETURN_NOT_OK(InferDecimalPrecisionAndScale(object, &precision, &scale)); + RETURN_NOT_OK(internal::InferDecimalPrecisionAndScale(object, &precision, &scale)); type_ = std::make_shared(precision, scale); @@ -672,7 +672,7 @@ Status NumPyConverter::ConvertDecimals() { object = objects[i]; if (PyObject_IsInstance(object, Decimal.obj())) { std::string string; - RETURN_NOT_OK(PythonDecimalToString(object, &string)); + RETURN_NOT_OK(internal::PythonDecimalToString(object, &string)); Decimal128 value; RETURN_NOT_OK(Decimal128::FromString(string, &value)); @@ -823,7 +823,7 @@ Status NumPyConverter::ConvertObjectFixedWidthBytes( const std::shared_ptr& type) { PyAcquireGIL lock; - int32_t byte_width = static_cast(*type).byte_width(); + const int32_t byte_width = static_cast(*type).byte_width(); // The output type at this point is inconclusive because there may be bytes // and unicode mixed in the object array @@ -893,8 +893,8 @@ Status NumPyConverter::ConvertObjectsInfer() { OwnedRef decimal; OwnedRef Decimal; - RETURN_NOT_OK(ImportModule("decimal", &decimal)); - RETURN_NOT_OK(ImportFromModule(decimal, "Decimal", &Decimal)); + RETURN_NOT_OK(internal::ImportModule("decimal", &decimal)); + RETURN_NOT_OK(internal::ImportFromModule(decimal, "Decimal", &Decimal)); for (int64_t i = 0; i < length_; ++i) { PyObject* obj = objects[i]; @@ -935,7 +935,7 @@ Status NumPyConverter::ConvertObjectsInfer() { Status NumPyConverter::ConvertObjectsInferAndCast() { size_t position = out_arrays_.size(); RETURN_NOT_OK(ConvertObjectsInfer()); - + DCHECK_EQ(position + 1, out_arrays_.size()); std::shared_ptr arr = out_arrays_[position]; // Perform cast @@ -1182,10 +1182,10 @@ Status NumPyConverter::ConvertLists(const std::shared_ptr& type, LIST_CASE(DOUBLE, NPY_DOUBLE, DoubleType) LIST_CASE(STRING, NPY_OBJECT, StringType) case Type::LIST: { - const ListType& list_type = static_cast(*type); + const auto& list_type = static_cast(*type); auto value_builder = static_cast(builder->value_builder()); - auto foreach_item = [&](PyObject* object) { + auto foreach_item = [this, &builder, &value_builder, &list_type](PyObject* object) { if (PandasObjectIsNull(object)) { return builder->AppendNull(); } else { @@ -1219,8 +1219,9 @@ Status NdarrayToArrow(MemoryPool* pool, PyObject* ao, PyObject* mo, std::shared_ptr* out) { NumPyConverter converter(pool, ao, mo, type, use_pandas_null_sentinels); RETURN_NOT_OK(converter.Convert()); - DCHECK(converter.result()[0]); - *out = std::make_shared(converter.result()); + const auto& output_arrays = converter.result(); + DCHECK_GT(output_arrays.size(), 0); + *out = std::make_shared(output_arrays); return Status::OK(); } diff --git a/cpp/src/arrow/python/python-test.cc b/cpp/src/arrow/python/python-test.cc index e1796c097d6..86391a18598 100644 --- a/cpp/src/arrow/python/python-test.cc +++ b/cpp/src/arrow/python/python-test.cc @@ -39,10 +39,10 @@ TEST(DecimalTest, TestPythonDecimalToString) { OwnedRef decimal; OwnedRef Decimal; - ASSERT_OK(ImportModule("decimal", &decimal)); + ASSERT_OK(internal::ImportModule("decimal", &decimal)); ASSERT_NE(decimal.obj(), nullptr); - ASSERT_OK(ImportFromModule(decimal, "Decimal", &Decimal)); + ASSERT_OK(internal::ImportFromModule(decimal, "Decimal", &Decimal)); ASSERT_NE(Decimal.obj(), nullptr); std::string decimal_string("-39402950693754869342983"); @@ -61,7 +61,7 @@ TEST(DecimalTest, TestPythonDecimalToString) { ASSERT_NE(python_object, nullptr); std::string string_result; - ASSERT_OK(PythonDecimalToString(python_object, &string_result)); + ASSERT_OK(internal::PythonDecimalToString(python_object, &string_result)); } TEST(PandasConversionTest, TestObjectBlockWriteFails) { diff --git a/cpp/src/arrow/table-test.cc b/cpp/src/arrow/table-test.cc index b0aeed1925e..b490310c26a 100644 --- a/cpp/src/arrow/table-test.cc +++ b/cpp/src/arrow/table-test.cc @@ -140,10 +140,6 @@ TEST_F(TestColumn, BasicAPI) { ASSERT_EQ(300, column_->length()); ASSERT_EQ(30, column_->null_count()); ASSERT_EQ(3, column_->data()->num_chunks()); - - // nullptr array should not break - column_.reset(new Column(f0, std::shared_ptr(nullptr))); - ASSERT_NE(column_.get(), nullptr); } TEST_F(TestColumn, ChunksInhomogeneous) { diff --git a/cpp/src/arrow/table.cc b/cpp/src/arrow/table.cc index d0bbe7e0ec9..009b5cf6373 100644 --- a/cpp/src/arrow/table.cc +++ b/cpp/src/arrow/table.cc @@ -42,6 +42,8 @@ ChunkedArray::ChunkedArray(const ArrayVector& chunks) : chunks_(chunks) { } } +std::shared_ptr ChunkedArray::type() const { return chunks_[0]->type(); } + bool ChunkedArray::Equals(const ChunkedArray& other) const { if (length_ != other.length()) { return false; @@ -105,10 +107,10 @@ Column::Column(const std::shared_ptr& field, const ArrayVector& chunks) Column::Column(const std::shared_ptr& field, const std::shared_ptr& data) : field_(field) { - if (data) { - data_ = std::make_shared(ArrayVector({data})); - } else { + if (!data) { data_ = std::make_shared(ArrayVector({})); + } else { + data_ = std::make_shared(ArrayVector({data})); } } @@ -192,6 +194,7 @@ std::shared_ptr RecordBatch::column(int i) const { if (!boxed_columns_[i]) { DCHECK(MakeArray(columns_[i], &boxed_columns_[i]).ok()); } + DCHECK(boxed_columns_[i]); return boxed_columns_[i]; } diff --git a/cpp/src/arrow/table.h b/cpp/src/arrow/table.h index 85fa2341a82..324112bfb3e 100644 --- a/cpp/src/arrow/table.h +++ b/cpp/src/arrow/table.h @@ -53,7 +53,7 @@ class ARROW_EXPORT ChunkedArray { const ArrayVector& chunks() const { return chunks_; } - std::shared_ptr type() const { return chunks_[0]->type(); } + std::shared_ptr type() const; bool Equals(const ChunkedArray& other) const; bool Equals(const std::shared_ptr& other) const; diff --git a/cpp/src/arrow/util/bit-util.cc b/cpp/src/arrow/util/bit-util.cc index 15bf3595a96..e0116cc567b 100644 --- a/cpp/src/arrow/util/bit-util.cc +++ b/cpp/src/arrow/util/bit-util.cc @@ -31,6 +31,7 @@ #include "arrow/memory_pool.h" #include "arrow/status.h" #include "arrow/util/bit-util.h" +#include "arrow/util/logging.h" namespace arrow { @@ -48,9 +49,9 @@ Status BitUtil::BytesToBits(const std::vector& bytes, MemoryPool* pool, std::shared_ptr buffer; RETURN_NOT_OK(AllocateBuffer(pool, bit_length, &buffer)); - - memset(buffer->mutable_data(), 0, static_cast(bit_length)); - FillBitsFromBytes(bytes, buffer->mutable_data()); + uint8_t* out_buf = buffer->mutable_data(); + memset(out_buf, 0, static_cast(bit_length)); + FillBitsFromBytes(bytes, out_buf); *out = buffer; return Status::OK(); diff --git a/cpp/src/arrow/util/key_value_metadata.cc b/cpp/src/arrow/util/key_value_metadata.cc index cf74ddf37b4..4f379537c48 100644 --- a/cpp/src/arrow/util/key_value_metadata.cc +++ b/cpp/src/arrow/util/key_value_metadata.cc @@ -89,12 +89,14 @@ int64_t KeyValueMetadata::size() const { std::string KeyValueMetadata::key(int64_t i) const { DCHECK_GE(i, 0); - return keys_[static_cast(i)]; + DCHECK_LT(static_cast(i), keys_.size()); + return keys_[i]; } std::string KeyValueMetadata::value(int64_t i) const { DCHECK_GE(i, 0); - return values_[static_cast(i)]; + DCHECK_LT(static_cast(i), values_.size()); + return values_[i]; } std::shared_ptr KeyValueMetadata::Copy() const { diff --git a/cpp/src/arrow/util/logging.h b/cpp/src/arrow/util/logging.h index 40a51cb5569..39815f30315 100644 --- a/cpp/src/arrow/util/logging.h +++ b/cpp/src/arrow/util/logging.h @@ -45,7 +45,7 @@ namespace arrow { #define ARROW_CHECK(condition) \ (condition) ? 0 \ : ::arrow::internal::FatalLog(ARROW_FATAL) \ - << __FILE__ << __LINE__ << " Check failed: " #condition " " + << __FILE__ << ":" << __LINE__ << " Check failed: " #condition " " #ifdef NDEBUG #define ARROW_DFATAL ARROW_WARNING diff --git a/cpp/src/plasma/client.cc b/cpp/src/plasma/client.cc index 3f99fe04708..e57a2a6f300 100644 --- a/cpp/src/plasma/client.cc +++ b/cpp/src/plasma/client.cc @@ -356,6 +356,7 @@ Status PlasmaClient::Contains(const ObjectID& object_id, bool* has_object) { std::vector buffer; RETURN_NOT_OK(PlasmaReceive(store_conn_, MessageType_PlasmaContainsReply, &buffer)); ObjectID object_id2; + DCHECK_GT(buffer.size(), 0); RETURN_NOT_OK( ReadContainsReply(buffer.data(), buffer.size(), &object_id2, has_object)); } diff --git a/cpp/src/plasma/fling.cc b/cpp/src/plasma/fling.cc index 14db32085c0..b84648b25a9 100644 --- a/cpp/src/plasma/fling.cc +++ b/cpp/src/plasma/fling.cc @@ -37,6 +37,9 @@ int send_fd(int conn, int fd) { init_msg(&msg, &iov, buf, sizeof(buf)); struct cmsghdr* header = CMSG_FIRSTHDR(&msg); + if (header == nullptr) { + return -1; + } header->cmsg_level = SOL_SOCKET; header->cmsg_type = SCM_RIGHTS; header->cmsg_len = CMSG_LEN(sizeof(int)); diff --git a/cpp/src/plasma/io.cc b/cpp/src/plasma/io.cc index fc0010b0631..afe7053329b 100644 --- a/cpp/src/plasma/io.cc +++ b/cpp/src/plasma/io.cc @@ -224,6 +224,7 @@ uint8_t* read_message_async(int sock) { uint8_t* message = reinterpret_cast(malloc(size)); s = ReadBytes(sock, message, size); if (!s.ok()) { + free(message); /* The other side has closed the socket. */ ARROW_LOG(DEBUG) << "Socket has been closed, or some other error has occurred."; close(sock); diff --git a/cpp/src/plasma/store.cc b/cpp/src/plasma/store.cc index 72d199ba465..210cce16238 100644 --- a/cpp/src/plasma/store.cc +++ b/cpp/src/plasma/store.cc @@ -665,7 +665,7 @@ class PlasmaStoreRunner { std::unique_ptr store_; }; -static PlasmaStoreRunner* g_runner = nullptr; +static std::unique_ptr g_runner = nullptr; void HandleSignal(int signal) { if (signal == SIGTERM) { @@ -683,10 +683,9 @@ void start_server(char* socket_name, int64_t system_memory, std::string plasma_d // to a client that has already died, the store could die. signal(SIGPIPE, SIG_IGN); - PlasmaStoreRunner runner; - g_runner = &runner; + g_runner.reset(new PlasmaStoreRunner()); signal(SIGTERM, HandleSignal); - runner.Start(socket_name, system_memory, plasma_directory, hugepages_enabled); + g_runner->Start(socket_name, system_memory, plasma_directory, hugepages_enabled); } } // namespace plasma