History

dnn/dnn_backend_native_layer_mathbinary: Fix leak upon error

Fixes Coverity issue #1473568.

Andreas Rheinhardt committed 5 years ago

Commit 2f056de1 parent 723ebf01 file · +11 −12Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/dnn/dnn_backend_native_layer_mathbinary.c+11−12
@@ -100,20 +100,17 @@ static void math_binary_not_commutative(FunType pfun, const DnnLayerMathBinaryPa · 99 unmodified lines
100100 }
101101 int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
102102 {
103− DnnLayerMathBinaryParams *params;
103+ DnnLayerMathBinaryParams params = { 0 };
104104 int dnn_size = 0;
105105 int input_index = 0;
106− params = av_malloc(sizeof(*params));
107− if (!params)
108− return 0;
109106
110− params->bin_op = (int32_t)avio_rl32(model_file_context);
107+ params.bin_op = (int32_t)avio_rl32(model_file_context);
111108 dnn_size += 4;
112109
113− params->input0_broadcast = (int32_t)avio_rl32(model_file_context);
110+ params.input0_broadcast = (int32_t)avio_rl32(model_file_context);
114111 dnn_size += 4;
115− if (params->input0_broadcast) {
116− params->v = av_int2float(avio_rl32(model_file_context));
112+ if (params.input0_broadcast) {
113+ params.v = av_int2float(avio_rl32(model_file_context));
117114 } else {
118115 layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context);
119116 if (layer->input_operand_indexes[input_index] >= operands_num) {
@@ -123,10 +120,10 @@ int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, · 3 unmodified lines
123120 }
124121 dnn_size += 4;
125122
126− params->input1_broadcast = (int32_t)avio_rl32(model_file_context);
123+ params.input1_broadcast = (int32_t)avio_rl32(model_file_context);
127124 dnn_size += 4;
128− if (params->input1_broadcast) {
129− params->v = av_int2float(avio_rl32(model_file_context));
125+ if (params.input1_broadcast) {
126+ params.v = av_int2float(avio_rl32(model_file_context));
130127 } else {
131128 layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context);
132129 if (layer->input_operand_indexes[input_index] >= operands_num) {
@@ -138,11 +135,13 @@ int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, · 5 unmodified lines
138135
139136 layer->output_operand_index = (int32_t)avio_rl32(model_file_context);
140137 dnn_size += 4;
141− layer->params = params;
142138
143139 if (layer->output_operand_index >= operands_num) {
144140 return 0;
145141 }
142+ layer->params = av_memdup(&params, sizeof(params));
143+ if (!layer->params)
144+ return 0;
146145
147146 return dnn_size;
148147 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t