diff options
| author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-10-09 15:14:52 (GMT) | 
|---|---|---|
| committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-10-09 15:14:52 (GMT) | 
| commit | 15a63878139ab900f4506e1d42db53e710793dff (patch) | |
| tree | 51d925998c054c3a89b0e99d5abc71b8efe1e4b8 /src | |
| parent | 5efad15b0254e6b2dc213865e88d8a1ea7419454 (diff) | |
Fix memory issues.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/tng_io.c | 34 | 
1 files changed, 32 insertions, 2 deletions
| diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index a4fe668..9acd857 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -2316,6 +2316,11 @@ static tng_function_status tng_molecules_block_read                  printf("Cannot allocate memory (%"PRId64" bytes). %s: %d\n",                      molecule->n_residues * sizeof(struct tng_residue),                      __FILE__, __LINE__); +                if(molecule->chains) +                { +                    free(molecule->chains); +                    molecule->chains = 0; +                }                  return(TNG_CRITICAL);              } @@ -2333,6 +2338,16 @@ static tng_function_status tng_molecules_block_read              printf("Cannot allocate memory (%"PRId64" bytes). %s: %d\n",                     molecule->n_atoms * sizeof(struct tng_atom),                     __FILE__, __LINE__); +            if(molecule->chains) +            { +                free(molecule->chains); +                molecule->chains = 0; +            } +            if(molecule->residues) +            { +                free(molecule->residues); +                molecule->residues = 0; +            }              return(TNG_CRITICAL);          } @@ -2428,6 +2443,21 @@ static tng_function_status tng_molecules_block_read              printf("Cannot allocate memory (%"PRId64" bytes). %s: %d\n",                     molecule->n_bonds * sizeof(struct tng_bond),                     __FILE__, __LINE__); +            if(molecule->chains) +            { +                free(molecule->chains); +                molecule->chains = 0; +            } +            if(molecule->residues) +            { +                free(molecule->residues); +                molecule->residues = 0; +            } +            if(molecule->bonds) +            { +                free(molecule->bonds); +                molecule->bonds = 0; +            }              return(TNG_CRITICAL);          } @@ -7778,7 +7808,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init(tng_trajectory_t *tng_      tng_trajectory_t tng_data;      *tng_data_p = malloc(sizeof(struct tng_trajectory)); -    if(!tng_data_p) +    if(!*tng_data_p)      {          printf("Cannot allocate memory (%lu bytes). %s: %d\n",                 sizeof(struct tng_trajectory), __FILE__, __LINE__); @@ -8307,7 +8337,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src(tng_trajector      tng_trajectory_t dest;      *dest_p = malloc(sizeof(struct tng_trajectory)); -    if(!dest_p) +    if(!*dest_p)      {          printf("Cannot allocate memory (%lu bytes). %s: %d\n",                 sizeof(struct tng_trajectory), __FILE__, __LINE__); | 
