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
100}100}
101int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)101int ff_dnn_load_layer_math_binary(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
102{102{
103 DnnLayerMathBinaryParams *params;103 DnnLayerMathBinaryParams params = { 0 };
104 int dnn_size = 0;104 int dnn_size = 0;
105 int input_index = 0;105 int input_index = 0;
106 params = av_malloc(sizeof(*params));
107 if (!params)
108 return 0;
109 106
110 params->bin_op = (int32_t)avio_rl32(model_file_context);107 params.bin_op = (int32_t)avio_rl32(model_file_context);
111 dnn_size += 4;108 dnn_size += 4;
112 109
113 params->input0_broadcast = (int32_t)avio_rl32(model_file_context);110 params.input0_broadcast = (int32_t)avio_rl32(model_file_context);
114 dnn_size += 4;111 dnn_size += 4;
115 if (params->input0_broadcast) {112 if (params.input0_broadcast) {
116 params->v = av_int2float(avio_rl32(model_file_context));113 params.v = av_int2float(avio_rl32(model_file_context));
117 } else {114 } else {
118 layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context);115 layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context);
119 if (layer->input_operand_indexes[input_index] >= operands_num) {116 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
123 }120 }
124 dnn_size += 4;121 dnn_size += 4;
125 122
126 params->input1_broadcast = (int32_t)avio_rl32(model_file_context);123 params.input1_broadcast = (int32_t)avio_rl32(model_file_context);
127 dnn_size += 4;124 dnn_size += 4;
128 if (params->input1_broadcast) {125 if (params.input1_broadcast) {
129 params->v = av_int2float(avio_rl32(model_file_context));126 params.v = av_int2float(avio_rl32(model_file_context));
130 } else {127 } else {
131 layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context);128 layer->input_operand_indexes[input_index] = (int32_t)avio_rl32(model_file_context);
132 if (layer->input_operand_indexes[input_index] >= operands_num) {129 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
138 135
139 layer->output_operand_index = (int32_t)avio_rl32(model_file_context);136 layer->output_operand_index = (int32_t)avio_rl32(model_file_context);
140 dnn_size += 4;137 dnn_size += 4;
141 layer->params = params;
142 138
143 if (layer->output_operand_index >= operands_num) {139 if (layer->output_operand_index >= operands_num) {
144 return 0;140 return 0;
145 }141 }
142 layer->params = av_memdup(&params, sizeof(params));
143 if (!layer->params)
144 return 0;
146 145
147 return dnn_size;146 return dnn_size;
148}147}

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