address minor memory management issues

This commit is contained in:
Axel Kohlmeyer
2025-06-25 19:46:15 -04:00
parent 6934a31878
commit fce4006fda
2 changed files with 15 additions and 6 deletions

View File

@ -312,7 +312,10 @@ struct fft_plan_3d *fft_3d_create_plan(
plan->pre_plan = remap_3d_create_plan(comm,in_ilo,in_ihi,in_jlo,in_jhi,in_klo,in_khi,
first_ilo,first_ihi,first_jlo,first_jhi,
first_klo,first_khi,2,0,0,FFT_PRECISION,0);
if (plan->pre_plan == nullptr) return nullptr;
if (plan->pre_plan == nullptr) {
free(plan);
return nullptr;
}
}
// 1d FFTs along fast axis

View File

@ -125,8 +125,8 @@ void remap_3d(FFT_SCALAR *in, FFT_SCALAR *out, FFT_SCALAR *buf,
for (int i=0;i<plan->nrecv;i++)
recvBufferSize += plan->recv_size[i];
auto packedSendBuffer = (FFT_SCALAR *) malloc(sizeof(FFT_SCALAR) * sendBufferSize);
auto packedRecvBuffer = (FFT_SCALAR *) malloc(sizeof(FFT_SCALAR) * recvBufferSize);
auto packedSendBuffer = (FFT_SCALAR *) malloc(sizeof(FFT_SCALAR) * sendBufferSize + 1);
auto packedRecvBuffer = (FFT_SCALAR *) malloc(sizeof(FFT_SCALAR) * recvBufferSize + 1);
int *sendcnts = (int *) malloc(sizeof(int) * plan->commringlen);
int *rcvcnts = (int *) malloc(sizeof(int) * plan->commringlen);
@ -282,10 +282,16 @@ struct remap_plan_3d *remap_3d_create_plan(
// combine output extents across all procs
inarray = (struct extent_3d *) malloc(nprocs*sizeof(struct extent_3d));
if (inarray == nullptr) return nullptr;
if (inarray == nullptr) {
free(plan);
return nullptr;
}
outarray = (struct extent_3d *) malloc(nprocs*sizeof(struct extent_3d));
if (outarray == nullptr) return nullptr;
if (outarray == nullptr) {
free(plan);
return nullptr;
}
MPI_Allgather(&out,sizeof(struct extent_3d),MPI_BYTE,
outarray,sizeof(struct extent_3d),MPI_BYTE,comm);
@ -546,7 +552,7 @@ struct remap_plan_3d *remap_3d_create_plan(
// resize commringlist to final size
commringlist = (int *) realloc(commringlist, commringlen*sizeof(int));
commringlist = (int *) realloc(commringlist, commringlen*sizeof(int) + 1);
// set the plan->commringlist