Skip to content

Commit

Permalink
[Bug Fix] fix centerpoint malloc bug (#2099)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengshao0622 committed Jul 12, 2023
1 parent cf1ff20 commit c95fc1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions fastdeploy/vision/perception/paddle3d/centerpoint/preprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c95fc1f

Please sign in to comment.