-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Memory leak in libraries/AP_HAL_Linux/benchmarks/benchmark_videoin.cpp #8642
Copy link
Copy link
Closed
Description
Issue details
At line 26 and 53 of ardupilot-Copter-3.6/libraries/AP_HAL_Linux/benchmarks/benchmark_videoin.cpp, there can be memory leaks.
If the buffer variable is successfully allocated and then the new_buffer variable failed to allocate a heap space, the original source code just executes return.
It causes a memory leak because it skips free(buffer).
The line 53 of the source code file is also the same as above.
---------- Original source code ----------
static void BM_Crop8bpp(benchmark::State& state)
{
uint8_t *buffer, *new_buffer;
uint32_t width = 640;
uint32_t height = 480;
uint32_t left = width / 2 - state.range_x() / 2;
uint32_t top = height / 2 - state.range_y() / 2;
buffer = (uint8_t *)malloc(width * height);
if (!buffer) {
fprintf(stderr, "error: couldn't malloc buffer\n");
return;
}
new_buffer = (uint8_t *)malloc(state.range_x() * state.range_y());
if (!new_buffer) {
fprintf(stderr, "error: couldn't malloc new_buffer\n");
return;
}
while (state.KeepRunning()) {
Linux::VideoIn::crop_8bpp(buffer, new_buffer, width,
left, state.range_x(), top, state.range_y());
}
free(buffer);
free(new_buffer);
}
Version
ardupilot-Copter-3.6
Platform
[V] All
[ ] AntennaTracker
[ ] Copter
[ ] Plane
[ ] Rover
[ ] Submarine
Airframe type
Hardware type
Logs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels