loggerd: fix use after free and memory leaks (#19695)

* fix use after free and memory leaks

* cleanup

* fix typo

Co-authored-by: Comma Device <device@comma.ai>
albatross
Adeeb Shihadeh 2021-01-08 15:39:14 -08:00 committed by GitHub
parent d39d737ae0
commit 6b0890f128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 27 deletions

View File

@ -7,9 +7,9 @@ libs = ['zmq', 'capnp', 'kj', 'z',
if arch in ["aarch64", "larch64"]:
src += ['encoder.cc']
libs += ['OmxVenc', 'OmxCore', 'gsl', 'CB'] + gpucommon
libs += ['OmxCore', 'gsl', 'CB'] + gpucommon
if arch == "aarch64":
libs += ['cutils']
libs += ['OmxVenc', 'cutils']
else:
libs += ['pthread']
else:

View File

@ -16,7 +16,6 @@
#include <OMX_QCOMExtns.h>
#include <libyuv.h>
#include <msm_media_info.h>
#include "common/mutex.h"
@ -25,10 +24,6 @@
#include "encoder.h"
// encoder: lossey codec using hardware hevc
// ***** OMX callback functions *****
static void wait_for_state(EncoderState *s, OMX_STATETYPE state) {
@ -282,26 +277,26 @@ void encoder_init(EncoderState *s, const char* filename, int width, int height,
assert(err == OMX_ErrorNone);
if (h265) {
// setup HEVC
#ifndef QCOM2
OMX_VIDEO_PARAM_HEVCTYPE hecv_type = {0};
OMX_INDEXTYPE index_type = (OMX_INDEXTYPE) OMX_IndexParamVideoHevc;
#else
OMX_VIDEO_PARAM_PROFILELEVELTYPE hecv_type = {0};
OMX_INDEXTYPE index_type = OMX_IndexParamVideoProfileLevelCurrent;
#endif
hecv_type.nSize = sizeof(hecv_type);
hecv_type.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
err = OMX_GetParameter(s->handle, index_type,
(OMX_PTR) &hecv_type);
assert(err == OMX_ErrorNone);
// setup HEVC
#ifndef QCOM2
OMX_VIDEO_PARAM_HEVCTYPE hevc_type = {0};
OMX_INDEXTYPE index_type = (OMX_INDEXTYPE) OMX_IndexParamVideoHevc;
#else
OMX_VIDEO_PARAM_PROFILELEVELTYPE hevc_type = {0};
OMX_INDEXTYPE index_type = OMX_IndexParamVideoProfileLevelCurrent;
#endif
hevc_type.nSize = sizeof(hevc_type);
hevc_type.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
err = OMX_GetParameter(s->handle, index_type,
(OMX_PTR) &hevc_type);
assert(err == OMX_ErrorNone);
hecv_type.eProfile = OMX_VIDEO_HEVCProfileMain;
hecv_type.eLevel = OMX_VIDEO_HEVCHighTierLevel5;
hevc_type.eProfile = OMX_VIDEO_HEVCProfileMain;
hevc_type.eLevel = OMX_VIDEO_HEVCHighTierLevel5;
err = OMX_SetParameter(s->handle, index_type,
(OMX_PTR) &hecv_type);
assert(err == OMX_ErrorNone);
err = OMX_SetParameter(s->handle, index_type,
(OMX_PTR) &hevc_type);
assert(err == OMX_ErrorNone);
} else {
// setup h264
OMX_VIDEO_PARAM_AVCTYPE avc = { 0 };
@ -588,11 +583,11 @@ void encoder_open(EncoderState *s, const char* path) {
} else {
s->of = fopen(s->vid_path, "wb");
assert(s->of);
if (s->codec_config_len > 0) {
#ifndef QCOM2
if (s->codec_config_len > 0) {
fwrite(s->codec_config, s->codec_config_len, 1, s->of);
#endif
}
#endif
}
// create camera lock file
@ -699,6 +694,13 @@ void encoder_destroy(EncoderState *s) {
err = OMX_FreeHandle(s->handle);
assert(err == OMX_ErrorNone);
while (queue_try_pop(&s->free_in));
while (queue_try_pop(&s->done_out));
if (s->codec_config) {
free(s->codec_config);
}
if (s->downscale) {
free(s->y_ptr2);
free(s->u_ptr2);

View File

@ -14,6 +14,9 @@ extern "C" {
#include "common/cqueue.h"
#include "visionipc.h"
// encoder: lossey codec using hardware hevc
struct EncoderState {
pthread_mutex_t lock;
int width, height, fps;