Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
Minor fixes : memory leak, free -> delete (#378)
Browse files Browse the repository at this point in the history
* Clean up interleave_info.
* No need to allocate nodeindices for artificial cells.
* Two allocation methods in use for int arrays in InterleaveInfo.
* No need for virtual destructor.
  • Loading branch information
nrnhines authored Aug 18, 2020
1 parent 543878e commit e9a7b19
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions coreneuron/io/nrn_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ void nrn_cleanup() {
if (!corenrn.get_pnttype2presyn().empty()) {
corenrn.get_pnttype2presyn().clear();
}

destroy_interleave_info();
}

void delete_trajectory_requests(NrnThread& nt) {
Expand Down
5 changes: 4 additions & 1 deletion coreneuron/io/phase2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ void Phase2::read_direct(int thread_id, const NrnThread& nt) {
offset = nrn_soa_byte_align(offset);

tml.type = type;
tml.nodeindices.resize(nodecounts[i]);
// artificial cell don't use nodeindices
if (!corenrn.get_is_artificial()[type]) {
tml.nodeindices.resize(nodecounts[i]);
}
tml.pdata.resize(nodecounts[i] * dparam_sizes[type]);

int* nodeindices_ = nullptr;
Expand Down
10 changes: 5 additions & 5 deletions coreneuron/permute/cellorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ InterleaveInfo::InterleaveInfo(const InterleaveInfo& info) {
nwarp = info.nwarp;
nstride = info.nstride;

copy_array(stridedispl, info.stridedispl, nwarp + 1);
copy_array(stride, info.stride, nstride);
copy_array(firstnode, info.firstnode, nwarp + 1);
copy_array(lastnode, info.lastnode, nwarp + 1);
copy_array(cellsize, info.cellsize, nwarp);
copy_align_array(stridedispl, info.stridedispl, nwarp + 1);
copy_align_array(stride, info.stride, nstride);
copy_align_array(firstnode, info.firstnode, nwarp + 1);
copy_align_array(lastnode, info.lastnode, nwarp + 1);
copy_align_array(cellsize, info.cellsize, nwarp);

copy_array(nnode, info.nnode, nwarp);
copy_array(ncycle, info.ncycle, nwarp);
Expand Down
10 changes: 9 additions & 1 deletion coreneuron/permute/cellorder.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef cellorder_h
#define cellorder_h

#include "coreneuron/utils/memory.h"
#include <algorithm>
namespace coreneuron {
int* interleave_order(int ith, int ncell, int nnode, int* parent);
Expand All @@ -14,7 +15,7 @@ class InterleaveInfo {
InterleaveInfo() = default;
InterleaveInfo(const InterleaveInfo&);
InterleaveInfo& operator=(const InterleaveInfo&);
virtual ~InterleaveInfo();
~InterleaveInfo();
int nwarp = 0; // used only by interleave2
int nstride = 0;
int* stridedispl = nullptr; // interleave2: nwarp+1
Expand Down Expand Up @@ -53,6 +54,13 @@ void copy_array(T*& dest, T* src, size_t n) {
std::copy(src, src + n, dest);
}

// copy src array to dest with NRN_SOA_BYTE_ALIGN ecalloc_align allocation
template <typename T>
void copy_align_array(T*& dest, T* src, size_t n) {
dest = (T*)ecalloc_align(n, sizeof(T));
std::copy(src, src + n, dest);
}

#define INTERLEAVE_DEBUG 0

#if INTERLEAVE_DEBUG
Expand Down

0 comments on commit e9a7b19

Please sign in to comment.