From c95fc1fba83b7b4aa2765cc0ad9e534d86c8b3fe Mon Sep 17 00:00:00 2001 From: zengshao0622 <108920665+zengshao0622@users.noreply.github.com> Date: Wed, 12 Jul 2023 17:17:22 +0800 Subject: [PATCH] [Bug Fix] fix centerpoint malloc bug (#2099) --- .../paddle3d/centerpoint/preprocessor.cc | 17 +++++++---------- .../paddle3d/centerpoint/preprocessor.h | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.cc b/fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.cc index c71c86c4f..4697d8ed3 100644 --- a/fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.cc +++ b/fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.cc @@ -24,7 +24,8 @@ CenterpointPreprocessor::CenterpointPreprocessor( bool CenterpointPreprocessor::ReadPoint(const std::string &file_path, const int64_t num_point_dim, - void **buffer, int64_t *num_points) { + std::vector &data, + int64_t *num_points) { std::ifstream file_in(file_path, std::ios::in | std::ios::binary); if (num_point_dim < 4) { FDERROR << "Point dimension must not be less than 4, but received " @@ -41,12 +42,8 @@ bool CenterpointPreprocessor::ReadPoint(const std::string &file_path, file_size = file_in.tellg(); file_in.seekg(0, std::ios::beg); - *buffer = malloc(file_size); - if (*buffer == nullptr) { - FDERROR << "Failed to malloc memory of size: " << file_size << std::endl; - return false; - } - file_in.read(reinterpret_cast(*buffer), file_size); + data.resize(file_size / sizeof(float)); + file_in.read(reinterpret_cast(data.data()), file_size); file_in.close(); if (file_size / sizeof(float) % num_point_dim != 0) { @@ -75,12 +72,12 @@ bool CenterpointPreprocessor::Apply(std::vector &points_dir, for (int index = 0; index < points_dir.size(); ++index) { std::string file_path = points_dir[index]; std::vector points_shape; - void *buffer = nullptr; + std::vector data; int64_t num_points; - if (!ReadPoint(file_path, num_point_dim, &buffer, &num_points)) { + if (!ReadPoint(file_path, num_point_dim, data, &num_points)) { return false; } - float *points = static_cast(buffer); + float *points = data.data(); if (!with_timelag && num_point_dim == 5 || num_point_dim > 5) { InsertTimeToPoints(num_points, num_point_dim, points); diff --git a/fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.h b/fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.h index c747eeae3..5fe785a88 100644 --- a/fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.h +++ b/fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.h @@ -51,7 +51,7 @@ class FASTDEPLOY_DECL CenterpointPreprocessor : public ProcessorManager { std::vector> processors_; bool ReadPoint(const std::string &file_path, const int64_t num_point_dim, - void **buffer, int64_t *num_points); + std::vector &data, int64_t *num_points); bool InsertTimeToPoints(const int64_t num_points, const int64_t num_point_dim, float *points);