mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-07-14 09:22:05 +08:00
Make sure memory is released by using unique_ptr (#1958)
This commit is contained in:
@@ -9,9 +9,6 @@
|
||||
#include "common/params.h"
|
||||
#include "driving.h"
|
||||
|
||||
|
||||
|
||||
|
||||
#define PATH_IDX 0
|
||||
#define LL_IDX PATH_IDX + MODEL_PATH_DISTANCE*2 + 1
|
||||
#define RL_IDX LL_IDX + MODEL_PATH_DISTANCE*2 + 2
|
||||
@@ -48,17 +45,14 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int t
|
||||
#endif
|
||||
|
||||
#ifdef DESIRE
|
||||
s->prev_desire = (float*)malloc(DESIRE_LEN * sizeof(float));
|
||||
for (int i = 0; i < DESIRE_LEN; i++) s->prev_desire[i] = 0.0;
|
||||
s->pulse_desire = (float*)malloc(DESIRE_LEN * sizeof(float));
|
||||
for (int i = 0; i < DESIRE_LEN; i++) s->pulse_desire[i] = 0.0;
|
||||
s->m->addDesire(s->pulse_desire, DESIRE_LEN);
|
||||
s->prev_desire = std::make_unique<float[]>(DESIRE_LEN);
|
||||
s->pulse_desire = std::make_unique<float[]>(DESIRE_LEN);
|
||||
s->m->addDesire(s->pulse_desire.get(), DESIRE_LEN);
|
||||
#endif
|
||||
|
||||
#ifdef TRAFFIC_CONVENTION
|
||||
s->traffic_convention = (float*)malloc(TRAFFIC_CONVENTION_LEN * sizeof(float));
|
||||
for (int i = 0; i < TRAFFIC_CONVENTION_LEN; i++) s->traffic_convention[i] = 0.0;
|
||||
s->m->addTrafficConvention(s->traffic_convention, TRAFFIC_CONVENTION_LEN);
|
||||
s->traffic_convention = std::make_unique<float[]>(TRAFFIC_CONVENTION_LEN);
|
||||
s->m->addTrafficConvention(s->traffic_convention.get(), TRAFFIC_CONVENTION_LEN);
|
||||
|
||||
std::vector<char> result = read_db_bytes("IsRHD");
|
||||
if (result.size() > 0) {
|
||||
@@ -79,8 +73,6 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q,
|
||||
cl_mem yuv_cl, int width, int height,
|
||||
mat3 transform, void* sock,
|
||||
@@ -100,7 +92,6 @@ ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q,
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//for (int i = 0; i < OUTPUT_SIZE + TEMPORAL_SIZE; i++) { printf("%f ", s->output[i]); } printf("\n");
|
||||
|
||||
float *new_frame_buf = frame_prepare(&s->frame, q, yuv_cl, width, height, transform);
|
||||
@@ -163,7 +154,6 @@ void poly_fit(float *in_pts, float *in_stds, float *out, int valid_len) {
|
||||
out[3] = y0;
|
||||
}
|
||||
|
||||
|
||||
void fill_path(cereal::ModelData::PathData::Builder path, const float * data, bool has_prob, const float offset) {
|
||||
float points_arr[MODEL_PATH_DISTANCE];
|
||||
float stds_arr[MODEL_PATH_DISTANCE];
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "runners/run.h"
|
||||
|
||||
#include <czmq.h>
|
||||
#include <memory>
|
||||
#include "messaging.hpp"
|
||||
|
||||
#define MODEL_WIDTH 512
|
||||
@@ -58,11 +59,11 @@ typedef struct ModelState {
|
||||
float *input_frames;
|
||||
RunModel *m;
|
||||
#ifdef DESIRE
|
||||
float *prev_desire;
|
||||
float *pulse_desire;
|
||||
std::unique_ptr<float[]> prev_desire;
|
||||
std::unique_ptr<float[]> pulse_desire;
|
||||
#endif
|
||||
#ifdef TRAFFIC_CONVENTION
|
||||
float *traffic_convention;
|
||||
std::unique_ptr<float[]> traffic_convention;
|
||||
#endif
|
||||
} ModelState;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user