Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Memory leaks and smart pointers #21

Open
seunghwak opened this issue Jan 9, 2019 · 2 comments
Open

[BUG] Memory leaks and smart pointers #21

seunghwak opened this issue Jan 9, 2019 · 2 comments
Labels
? - Needs Triage bug Something isn't working

Comments

@seunghwak
Copy link
Collaborator

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.

@seunghwak seunghwak added bug Something isn't working ? - Needs Triage labels Jan 9, 2019
@ogreen
Copy link

ogreen commented Jan 10, 2019

We may get rid of this class (GraphStd) is it Hornet's static graph data structure and will become redundant with cuGraph and its CSR data structure.

@seunghwak
Copy link
Collaborator Author

seunghwak commented Jan 10, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
? - Needs Triage bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants