mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-13 04:13:58 +08:00
[Bug Fix] fix centerpoint malloc bug (#2099)
This commit is contained in:
@@ -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<float> &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<char *>(*buffer), file_size);
|
||||
data.resize(file_size / sizeof(float));
|
||||
file_in.read(reinterpret_cast<char *>(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<std::string> &points_dir,
|
||||
for (int index = 0; index < points_dir.size(); ++index) {
|
||||
std::string file_path = points_dir[index];
|
||||
std::vector<int64_t> points_shape;
|
||||
void *buffer = nullptr;
|
||||
std::vector<float> 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<float *>(buffer);
|
||||
float *points = data.data();
|
||||
|
||||
if (!with_timelag && num_point_dim == 5 || num_point_dim > 5) {
|
||||
InsertTimeToPoints(num_points, num_point_dim, points);
|
||||
|
@@ -51,7 +51,7 @@ class FASTDEPLOY_DECL CenterpointPreprocessor : public ProcessorManager {
|
||||
std::vector<std::shared_ptr<Processor>> processors_;
|
||||
bool ReadPoint(const std::string &file_path,
|
||||
const int64_t num_point_dim,
|
||||
void **buffer, int64_t *num_points);
|
||||
std::vector<float> &data, int64_t *num_points);
|
||||
bool InsertTimeToPoints(const int64_t num_points,
|
||||
const int64_t num_point_dim,
|
||||
float *points);
|
||||
|
Reference in New Issue
Block a user