Skip to content

Commit

Permalink
Handle potential write errors when printing trace indices
Browse files Browse the repository at this point in the history
  • Loading branch information
milianw committed Apr 23, 2018
1 parent 51f3ad7 commit d16bcef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/track/libheaptrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,14 @@ class HeapTrack
return;
}
updateModuleCache();
const auto index = s_data->traceTree.index(trace, s_data->out);

const auto index = s_data->traceTree.index(trace, [this](uintptr_t ip, uint32_t index) {
if (fprintf(s_data->out, "t %" PRIxPTR " %x\n", ip, index) < 0) {
writeError();
return false;
}
return true;
});

#ifdef DEBUG_MALLOC_PTRS
auto it = s_data->known.find(ptr);
Expand Down
9 changes: 6 additions & 3 deletions src/track/tracetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ class TraceTree
* Index the data in @p trace and return the index of the last instruction
* pointer.
*
* Unknown instruction pointers will be printed to @p out.
* Unknown instruction pointers will be handled by the @p callback
*/
uint32_t index(const Trace& trace, FILE* out)
template <typename Fun>
uint32_t index(const Trace& trace, Fun callback)
{
uint32_t index = 0;
TraceEdge* parent = &m_root;
Expand All @@ -76,7 +77,9 @@ class TraceTree
if (it == parent->children.end() || it->instructionPointer != ip) {
index = m_index++;
it = parent->children.insert(it, {ip, index, {}});
fprintf(out, "t %" PRIxPTR " %x\n", reinterpret_cast<uintptr_t>(ip), parent->index);
if (!callback(reinterpret_cast<uintptr_t>(ip), parent->index)) {
return 0;
}
}
index = it->index;
parent = &(*it);
Expand Down

0 comments on commit d16bcef

Please sign in to comment.