From 72a0cf5dfb7e1bbc39d05ca9ad520461add9be38 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Tue, 12 Mar 2019 13:18:37 -0600 Subject: [PATCH] fixed codacy warning --- src/clib/pio_getput_int.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/clib/pio_getput_int.c b/src/clib/pio_getput_int.c index 158ebe295c3..01f2a4102a2 100644 --- a/src/clib/pio_getput_int.c +++ b/src/clib/pio_getput_int.c @@ -1366,7 +1366,11 @@ int PIOc_put_var_tc(int ncid, int varid, nc_type xtype, const void *op) 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__); + } + /* Set up start array. */ for (int d = 0; d < ndims; d++) @@ -1374,19 +1378,33 @@ int PIOc_put_var_tc(int ncid, int varid, nc_type xtype, const void *op) /* Get the dimids for this var. */ if ((ierr = PIOc_inq_vardimid(ncid, varid, dimid))) + { + free(startp); + free(countp); return check_netcdf(file, ierr, __FILE__, __LINE__); + } /* Count array are the dimlens. */ for (int d = 0; d < ndims; d++) + { if ((ierr = PIOc_inq_dimlen(ncid, dimid[d], &countp[d]))) + { + free(startp); + free(countp); return pio_err(ios, file, ierr, __FILE__, __LINE__); + } + } } + /* Call the vars function. */ ierr = PIOc_put_vars_tc(ncid, varid, startp, countp, NULL, xtype, op); - if (startp != NULL) + + /* Free any allocated resources. */ + if (startp) free(startp); - if (countp != NULL) + if (countp) free(countp); + return ierr; }