ApolloAuto / apollo

An open autonomous driving platform
Apache License 2.0
25.01k stars 9.67k forks source link

memory leak in modules/planning/math/piecewise_jerk/piecewise_jerk_problem.cc #14421

Open acmol opened 2 years ago

acmol commented 2 years ago

Describe the bug

OSQPData* data = reinterpret_cast<OSQPData*>(c_malloc(sizeof(OSQPData)));

This variable data was never freed. The csc_matrixies was never freed neither.

void PiecewiseJerkProblem::FreeData(OSQPData* data) {
  delete[] data->q;
  delete[] data->l;
  delete[] data->u;

  delete[] data->P->i;
  delete[] data->P->p;
  delete[] data->P->x;
  c_free(data->P);

  delete[] data->A->i;
  delete[] data->A->p;
  delete[] data->A->x;
  c_free(data->A);

  c_free(data);
}

may fix this bug.

To Reproduce

You can use address sanitizer to examine the leaking.

I've started a pull request to fix a fd leak in https://github.com/ApolloAuto/apollo/pull/14309 , but no one cares my fixing. So I lost my patient on testing the fixing uppon. And just report the bug here - -, to fix or not, it's your decision.

zhaofuxie commented 2 years ago

maybe you have helped me to solve the coredump problem,according to your tips.

qwetqwe commented 2 years ago

Thanks for your pr, maybe you have solved the bug, could you add a new pr to fix it.We will merge into master