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>
pull/19591/head
Adeeb Shihadeh 4 years ago committed by GitHub
parent d39d737ae0
commit 6b0890f128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      selfdrive/loggerd/SConscript
  2. 52
      selfdrive/loggerd/encoder.cc
  3. 3
      selfdrive/loggerd/encoder.h

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

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

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

Loading…
Cancel
Save