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

Commit e9a7b19

Browse files
authored
Minor fixes : memory leak, free -> delete (#378)
* 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.
1 parent 543878e commit e9a7b19

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

coreneuron/io/nrn_setup.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ void nrn_cleanup() {
834834
if (!corenrn.get_pnttype2presyn().empty()) {
835835
corenrn.get_pnttype2presyn().clear();
836836
}
837+
838+
destroy_interleave_info();
837839
}
838840

839841
void delete_trajectory_requests(NrnThread& nt) {

coreneuron/io/phase2.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ void Phase2::read_direct(int thread_id, const NrnThread& nt) {
277277
offset = nrn_soa_byte_align(offset);
278278

279279
tml.type = type;
280-
tml.nodeindices.resize(nodecounts[i]);
280+
// artificial cell don't use nodeindices
281+
if (!corenrn.get_is_artificial()[type]) {
282+
tml.nodeindices.resize(nodecounts[i]);
283+
}
281284
tml.pdata.resize(nodecounts[i] * dparam_sizes[type]);
282285

283286
int* nodeindices_ = nullptr;

coreneuron/permute/cellorder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ InterleaveInfo::InterleaveInfo(const InterleaveInfo& info) {
4040
nwarp = info.nwarp;
4141
nstride = info.nstride;
4242

43-
copy_array(stridedispl, info.stridedispl, nwarp + 1);
44-
copy_array(stride, info.stride, nstride);
45-
copy_array(firstnode, info.firstnode, nwarp + 1);
46-
copy_array(lastnode, info.lastnode, nwarp + 1);
47-
copy_array(cellsize, info.cellsize, nwarp);
43+
copy_align_array(stridedispl, info.stridedispl, nwarp + 1);
44+
copy_align_array(stride, info.stride, nstride);
45+
copy_align_array(firstnode, info.firstnode, nwarp + 1);
46+
copy_align_array(lastnode, info.lastnode, nwarp + 1);
47+
copy_align_array(cellsize, info.cellsize, nwarp);
4848

4949
copy_array(nnode, info.nnode, nwarp);
5050
copy_array(ncycle, info.ncycle, nwarp);

coreneuron/permute/cellorder.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef cellorder_h
22
#define cellorder_h
33

4+
#include "coreneuron/utils/memory.h"
45
#include <algorithm>
56
namespace coreneuron {
67
int* interleave_order(int ith, int ncell, int nnode, int* parent);
@@ -14,7 +15,7 @@ class InterleaveInfo {
1415
InterleaveInfo() = default;
1516
InterleaveInfo(const InterleaveInfo&);
1617
InterleaveInfo& operator=(const InterleaveInfo&);
17-
virtual ~InterleaveInfo();
18+
~InterleaveInfo();
1819
int nwarp = 0; // used only by interleave2
1920
int nstride = 0;
2021
int* stridedispl = nullptr; // interleave2: nwarp+1
@@ -53,6 +54,13 @@ void copy_array(T*& dest, T* src, size_t n) {
5354
std::copy(src, src + n, dest);
5455
}
5556

57+
// copy src array to dest with NRN_SOA_BYTE_ALIGN ecalloc_align allocation
58+
template <typename T>
59+
void copy_align_array(T*& dest, T* src, size_t n) {
60+
dest = (T*)ecalloc_align(n, sizeof(T));
61+
std::copy(src, src + n, dest);
62+
}
63+
5664
#define INTERLEAVE_DEBUG 0
5765

5866
#if INTERLEAVE_DEBUG

0 commit comments

Comments
 (0)