iqbal-lab / Mykrobe-predictor

Antibiotic resistance predictions in minutes on a laptop
Other
50 stars 19 forks source link

Missing checks for malloc failures #59

Closed iqbal-lab closed 8 years ago

iqbal-lab commented 9 years ago

eg this in base_species.c

boolean* create_mask(boolean default_value) { boolean* mask = malloc(NUM_SPECIES * sizeof(boolean));

Should check afterwards eg

if (mask==NULL) { fail or return error message }

Ties into bigger picture of improving error handling being passed back to app

iqbal-lab commented 9 years ago

Actually, given the mask is an array of length NUM_SPECIES of booleans, we are basically talking about ~50 bools. Maybe at worst 200 booleans, right? I'd be tempted to do it on the stack. Not a big deal either way. The other option is to change code from

Species get_best_MTBC_species(SpeciesInfo* species_info ){ boolean* mask = create_MTBC_mask(); int species_enum = get_best_hit(species_info->species_covg_info,mask); Species species = species_enum; return (species); }

to

Species get_best_MTBC_species(SpeciesInfo* species_info ){ boolean* mask = create_MTBC_mask(); int species_enum = get_best_hit(species_info->species_covg_info,mask); free(mask); Species species = species_enum; return (species); }

iqbal-lab commented 9 years ago

OK, in all cases the fix is very simple - leaving this to fix after ECCMOD

iqbal-lab commented 8 years ago

Phelim, is this still open?

Phelimb commented 8 years ago

I think so. Will take a look on dev and fix before merging to master.