[fix] calloc instead of malloc when performing initialization on structs that may fail halfway and need to clean up while partially initialized (calloc will set all the bytes to zero so the member pointers are NULL instead of garbage memory)
This commit is contained in:
@@ -389,7 +389,7 @@ bool averaged_perceptron_trainer_train_example(averaged_perceptron_trainer_t *se
|
||||
}
|
||||
|
||||
averaged_perceptron_trainer_t *averaged_perceptron_trainer_new(void) {
|
||||
averaged_perceptron_trainer_t *self = malloc(sizeof(averaged_perceptron_trainer_t));
|
||||
averaged_perceptron_trainer_t *self = calloc(1, sizeof(averaged_perceptron_trainer_t));
|
||||
|
||||
if (self == NULL) return NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user