Skip to content

Commit

Permalink
fixed memory leak on error warning from codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Mar 25, 2019
1 parent b9259f3 commit ed7a0ee
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/clib/pio_getput_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,10 @@ int PIOc_get_var_tc(int ncid, int varid, nc_type xtype, void *buf)
if (!(startp = malloc(ndims * sizeof(PIO_Offset))))
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
if (!(countp = malloc(ndims * sizeof(PIO_Offset))))
{
free(startp);
return pio_err(ios, file, PIO_ENOMEM, __FILE__, __LINE__);
}

/* Find the dimension lengths. */
for (int d = 0; d < ndims; d++)
Expand All @@ -886,9 +889,9 @@ int PIOc_get_var_tc(int ncid, int varid, nc_type xtype, void *buf)
}

ierr = PIOc_get_vars_tc(ncid, varid, startp, countp, NULL, xtype, buf);
if(startp != NULL)
if (startp)
free(startp);
if(countp != NULL)
if (countp)
free(countp);
return ierr;

Expand Down

0 comments on commit ed7a0ee

Please sign in to comment.