Skip to content

Commit

Permalink
lstm: Fix explicit null dereferenced
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
stweil committed Dec 1, 2016
1 parent f3e8895 commit dfd7082
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lstm/lstmtrainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,18 @@ void LSTMTrainer::StartSubtrainer(STRING* log_msg) {
*log_msg += " Failed to revert to previous best for trial!";
delete sub_trainer_;
sub_trainer_ = NULL;
} else {
log_msg->add_str_int(" Trial sub_trainer_ from iteration ",
sub_trainer_->training_iteration());
// Reduce learning rate so it doesn't diverge this time.
sub_trainer_->ReduceLearningRates(this, log_msg);
// If it fails again, we will wait twice as long before reverting again.
int stall_offset = learning_iteration() - sub_trainer_->learning_iteration();
stall_iteration_ = learning_iteration() + 2 * stall_offset;
sub_trainer_->stall_iteration_ = stall_iteration_;
// Re-save the best trainer with the new learning rates and stall iteration.
checkpoint_writer_->Run(NO_BEST_TRAINER, sub_trainer_, &best_trainer_);
}
log_msg->add_str_int(" Trial sub_trainer_ from iteration ",
sub_trainer_->training_iteration());
// Reduce learning rate so it doesn't diverge this time.
sub_trainer_->ReduceLearningRates(this, log_msg);
// If it fails again, we will wait twice as long before reverting again.
int stall_offset = learning_iteration() - sub_trainer_->learning_iteration();
stall_iteration_ = learning_iteration() + 2 * stall_offset;
sub_trainer_->stall_iteration_ = stall_iteration_;
// Re-save the best trainer with the new learning rates and stall iteration.
checkpoint_writer_->Run(NO_BEST_TRAINER, sub_trainer_, &best_trainer_);
}

// While the sub_trainer_ is behind the current training iteration and its
Expand Down

0 comments on commit dfd7082

Please sign in to comment.