Skip to content

Commit 17095df

Browse files
author
Jacob Hegna
committed
Move interpreter check before modifying the allocation type.
1 parent 9d93a98 commit 17095df

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/Analysis/TFLiteUtils.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ TFModelEvaluatorImpl::TFModelEvaluatorImpl(
121121
tflite::InterpreterBuilder Builder(*Model, Resolver);
122122
Builder(&Interpreter);
123123

124+
if (!Interpreter) {
125+
invalidate();
126+
return;
127+
}
128+
124129
// We assume the input buffers are valid for the lifetime of the interpreter.
125130
// By default, tflite allocates memory in an arena and will periodically take
126131
// away memory and reallocate it in a different location after evaluations in
@@ -130,8 +135,7 @@ TFModelEvaluatorImpl::TFModelEvaluatorImpl(
130135
Interpreter->tensor(I)->allocation_type =
131136
TfLiteAllocationType::kTfLiteArenaRwPersistent;
132137

133-
if (!Interpreter ||
134-
Interpreter->AllocateTensors() != TfLiteStatus::kTfLiteOk) {
138+
if (Interpreter->AllocateTensors() != TfLiteStatus::kTfLiteOk) {
135139
invalidate();
136140
return;
137141
}

0 commit comments

Comments
 (0)