GPUSPH / gpusph

The world's first CUDA implementation of Weakly-Compressible Smoothed Particle Hydrodynamics
160 stars 67 forks source link

Minor memory leaks #37

Open sanguinariojoe opened 5 years ago

sanguinariojoe commented 5 years ago

In main.cc you are dynamically building the networkManager entity:

gdata.networkManager = new NetworkManager();

However, you are not checking if the memory has been correctly allocated (IDEM for the problem), and there are some exit conditions where the object is not removed:

    if (nm_worldsize > MAX_NODES_PER_CLUSTER) {
        cerr << "Too many nodes in cluster: " << nm_worldsize << " > " << MAX_NODES_PER_CLUSTER << endl;
        exit(1);
    }
(...)
        if (!gdata.clOptions->gpudirect) {
            // since H2D and D2H transfers have to wait for network transfers
            fprintf(stderr, "FATAL: asynchronous network transfers require --gpudirect\n");
            gdata.networkManager->finalizeNetwork();
            return 1;
        }

        if (gdata.devices > 1) {
            // since we were too lazy to implement a more complex mechanism
            fprintf(stderr, "FATAL: asynchronous network transfers only supported with 1 process per device\n");
            gdata.networkManager->finalizeNetwork();
            return 1;
        }

In NetworkManager.cc:70, you are in-place reallocating memory. If such operation fails, then the memory in m_requestsList is not realeased, and the pointer is nullified.