Only decrease leaked allocations counter for known allocations
authorMilian Wolff <mail@milianw.de>
Sun, 5 Mar 2017 21:52:23 +0000 (22:52 +0100)
committerMilian Wolff <mail@milianw.de>
Sun, 5 Mar 2017 21:52:23 +0000 (22:52 +0100)
When we runtime-attach heaptrack, we may encounter frees for
allocations that we did not track, i.e. those that happened before
we attached. In such cases, we used to decrase the leaked allocation
counter, and that potentially underflowed then. This is fixed now.

src/interpret/heaptrack_interpret.cpp

index 33e4c33..98477ce 100644 (file)
@@ -398,7 +398,6 @@ int main(int /*argc*/, char** /*argv*/)
             lastPtr = ptr;
             fprintf(stdout, "+ %x\n", index.index);
         } else if (reader.mode() == '-') {
-            --leakedAllocations;
             uint64_t ptr = 0;
             if (!(reader >> ptr)) {
                 cerr << "failed to parse line: " << reader.line() << endl;
@@ -414,6 +413,7 @@ int main(int /*argc*/, char** /*argv*/)
             if (temporary) {
                 ++temporaryAllocations;
             }
+            --leakedAllocations;
         } else {
             fputs(reader.line().c_str(), stdout);
             fputc('\n', stdout);