-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
In xlib/src/Graph/GraphStd.cpp
void GraphStd<vid_t, eoff_t>::COOtoCSR() {
...
247 if (_prop.is_directed_by_degree()) {
248 if (_prop.is_print())
249 std::cout << "Creating degree-directed graph ..." << std::endl;
250 eoff_t counter = 0;
251 vid_t u, v;
252 vid_t vid_small, vid_large;
253 degree_t deg_u, deg_v;
254 coo_t* coo_edges_tmp = new coo_t[_nE];
255 degree_t* _out_degrees_tmp = new degree_t[_nV]();
256 degree_t* _in_degrees_tmp;
257 if (_structure.is_reverse())
258 _in_degrees_tmp = new degree_t[_nV]();
259 for (eoff_t i=0; i<_nE; i++) {
260 u = _coo_edges[i].first;
261 v = _coo_edges[i].second;
262 deg_u = _out_degrees[u];
263 deg_v = _out_degrees[v];
264 if ((deg_u < deg_v) || ((deg_u == deg_v) && (u < v))) {
265 coo_edges_tmp[counter++] = {u, v};
266 }
267 }
268 _coo_edges = coo_edges_tmp;
269 _nE = counter;
270
271 if (_structure.is_directed() && _structure.is_reverse()) {
272 for (eoff_t i = 0; i < _nE; i++) {
273 _out_degrees_tmp[_coo_edges[i].first]++;
274 _in_degrees_tmp[_coo_edges[i].second]++;
275 }
276 }
277 else {
278 for (eoff_t i = 0; i < _nE; i++)
279 _out_degrees_tmp[_coo_edges[i].first]++;
280 }
281 _out_degrees = _out_degrees_tmp;
282 if (_structure.is_reverse())
283 _in_degrees = _in_degrees_tmp;
284 }
...
}
There are memory leaks in line 268, 281, and 283 (e.g. Memory pointed by _in_degrees dangles after executing _in_degrees = _in_degrees_tmp). I assume these are not the only memory leaks in the code. Using smart pointers (unique_ptr) can prevent this (e.g. if _in_degrees and _in_degrees_tmp are unique_ptr types, this is not a memory leak). We should consider replacing raw pointers with smart pointers or std:vector.