Skip to content

Commit

Permalink
fixed memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Mar 7, 2019
1 parent d85c2b7 commit 74d5da5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/clib/pioc_sc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void compute_one_dim(int gdim, int ioprocs, int rank, PIO_Offset *start,
* @param arrlen
* @param arr_in
* @returns the size of the block
* @author Jim Edwards
* @author Jim Edwards, Ed Hartnett
*/
PIO_Offset GCDblocksize(int arrlen, const PIO_Offset *arr_in)
{
Expand All @@ -150,6 +150,12 @@ PIO_Offset GCDblocksize(int arrlen, const PIO_Offset *arr_in)
/* Check inputs. */
pioassert(arrlen > 0 && arr_in, "invalid input", __FILE__, __LINE__);

/* Allocate arrays. */
if (!(loc_arr = malloc(sizeof(PIO_Offset) * (arrlen - 1))))
return PIO_ENOMEM;
if (!(del_arr = malloc(sizeof(PIO_Offset) * (arrlen - 1))))
return PIO_ENOMEM;

/* Count the number of contiguous blocks in arr_in. If any if
these blocks is of size 1, we are done and can return.
Otherwise numtimes is the number of blocks. */
Expand All @@ -160,16 +166,14 @@ PIO_Offset GCDblocksize(int arrlen, const PIO_Offset *arr_in)
{
numtimes++;
if ( i > 0 && del_arr[i - 1] > 1)
return(1);
{
free(loc_arr);
free(del_arr);
return 1;
}
}
}

/* Allocate arrays. */
if (!(loc_arr = malloc(sizeof(PIO_Offset) * (arrlen - 1))))
return PIO_ENOMEM;
if (!(del_arr = malloc(sizeof(PIO_Offset) * (arrlen - 1))))
return PIO_ENOMEM;

/* If numtimes is 0 the all of the data in arr_in is contiguous
* and numblks=1. Not sure why I have three different variables
* here, seems like n,numblks and numtimes could be combined. */
Expand Down

0 comments on commit 74d5da5

Please sign in to comment.