From ed7a0eea085f6291ec0b5eccfed51710d659fa13 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Mon, 25 Mar 2019 06:03:32 -0600 Subject: [PATCH] fixed memory leak on error warning from codacy --- src/clib/pio_getput_int.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/clib/pio_getput_int.c b/src/clib/pio_getput_int.c index 63541a679bf..0920ace33fd 100644 --- a/src/clib/pio_getput_int.c +++ b/src/clib/pio_getput_int.c @@ -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++) @@ -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;