Skip to content

Commit dfd7082

Browse files
committed
lstm: Fix explicit null dereferenced
Coverity report: CID 1366443 (#1 of 1): Explicit null dereferenced (FORWARD_NULL) 3. var_deref_model: Passing null pointer this->sub_trainer_ to training_iteration, which dereferences it. Signed-off-by: Stefan Weil <[email protected]>
1 parent f3e8895 commit dfd7082

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lstm/lstmtrainer.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -549,17 +549,18 @@ void LSTMTrainer::StartSubtrainer(STRING* log_msg) {
549549
*log_msg += " Failed to revert to previous best for trial!";
550550
delete sub_trainer_;
551551
sub_trainer_ = NULL;
552+
} else {
553+
log_msg->add_str_int(" Trial sub_trainer_ from iteration ",
554+
sub_trainer_->training_iteration());
555+
// Reduce learning rate so it doesn't diverge this time.
556+
sub_trainer_->ReduceLearningRates(this, log_msg);
557+
// If it fails again, we will wait twice as long before reverting again.
558+
int stall_offset = learning_iteration() - sub_trainer_->learning_iteration();
559+
stall_iteration_ = learning_iteration() + 2 * stall_offset;
560+
sub_trainer_->stall_iteration_ = stall_iteration_;
561+
// Re-save the best trainer with the new learning rates and stall iteration.
562+
checkpoint_writer_->Run(NO_BEST_TRAINER, sub_trainer_, &best_trainer_);
552563
}
553-
log_msg->add_str_int(" Trial sub_trainer_ from iteration ",
554-
sub_trainer_->training_iteration());
555-
// Reduce learning rate so it doesn't diverge this time.
556-
sub_trainer_->ReduceLearningRates(this, log_msg);
557-
// If it fails again, we will wait twice as long before reverting again.
558-
int stall_offset = learning_iteration() - sub_trainer_->learning_iteration();
559-
stall_iteration_ = learning_iteration() + 2 * stall_offset;
560-
sub_trainer_->stall_iteration_ = stall_iteration_;
561-
// Re-save the best trainer with the new learning rates and stall iteration.
562-
checkpoint_writer_->Run(NO_BEST_TRAINER, sub_trainer_, &best_trainer_);
563564
}
564565

565566
// While the sub_trainer_ is behind the current training iteration and its

0 commit comments

Comments
 (0)