1

This is my code. And I am getting error double free or corruption (fasttop) c++

//iterations
for (int iter=0;iter<iterations;iter++) {
    printf("Iteration %d\n",iter);
    printf("\tStreaming Edges\n");

    //for each edge which the source has a label but the destination has not. 
    //Assign the label to the matrix
    graph.stream_edges<VertexId>(
        [&](Edge & e){
            if ((vertices_labels[e.source]>=0) && (vertices_labels[e.target]<0)){
                aux_labels[e.target].push_back(vertices_labels[e.source]);
            } 
            return 0;
        }, nullptr, 0, 1
    );

    printf("\tStreaming Nodes\n");
    //get the most predominant vertice in the matrix
    graph.stream_vertices<VertexId>(
        [&](VertexId i){
            if (vertices_labels[i]<0){
                int maxCount = -1;
                int result = -1;
                for (int j=0;j<aux_labels[i].size();j++){
                    int value = aux_labels[i].at(j);
                    int c = 1;
                    for (int k=j+1;k<aux_labels[i].size();k++){
                        if (aux_labels[i].at(k)==value){
                            c++;
                            if (c>maxCount){
                                maxCount = c;
                                result = aux_labels[i].at(k);
                            }                           
                        }
                    }
                }
                write_add(&vertices_labels[i], result+1);
            }
            return 0;
        }
    );

}

can someone tell me where might be the problem? P.s. i am using Big vector. When I try to run it in Linux inside my virtual box of macbook, it runs fine. But when I try to run it Linux machine, it gives me error (double free or corruption (fasttop)). I believe that it occurs on real machine because of concurrency maybe. Any suggestion or insight is welcomed!

  • 2
    If you build with debug information (adding the `-g` flag when building) then the stack-trace should show file-names and line-numbers as well. Also use a memory debugger like [Valgrind](http://valgrind.org/). Both those things will help you locate *where* it happens. – Some programmer dude Jun 22 '17 at 13:14
  • 1
    If it happens with one configuration but not the other it's that you're lucky and that the error happens on one configuration (instead of not being detected). You should run your program in a debugger (gdb for example). It will give you more information about the error (where exactly it happens ...) – nefas Jun 22 '17 at 13:14
  • To complete _some programmer dude_ comment, you can use the sanitizer (on [gcc](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html) and [clang](https://clang.llvm.org/docs/index.html)). They give you information about the memory without the overhead of valgind (even if the sanitizer are not overhead-free) – nefas Jun 22 '17 at 13:18
  • The two things to check for are double free and writing past the end of a block. By commenting code in and out you can often isolate the error, though the tools suggested are also good and can make life easier. – Malcolm McLean Jun 22 '17 at 13:23
  • This code part seems completely irrelevant, since nothing is freed here, not even an implicit call to the `operator new` and `delete`. Are you sure the error is located in this code part? You can easily test it using someting like: `std::cout << __PRETTY_FUNCTION__ << ": " << __LINE__ << std::endl;` added to the key positions in your code. Also, make sure to create a minimal example test to find the bug more easily. – Adam Hunyadi Jun 22 '17 at 14:29
  • 1
    Possible duplicate of [How to track down a "double free or corruption" error](https://stackoverflow.com/questions/2902064/how-to-track-down-a-double-free-or-corruption-error) – Raedwald Dec 06 '18 at 13:26

0 Answers0