Skip to content

Commit

Permalink
Avoid mem leaks in counting includer test
Browse files Browse the repository at this point in the history
This is caught by leak checks in Clang 3.6 address sanitizer.
  • Loading branch information
dneto0 committed May 12, 2017
1 parent 44823cb commit dcb3036
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions libshaderc_util/src/counting_includer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,38 @@

#include "libshaderc_util/counting_includer.h"

#include <gmock/gmock.h>
#include <thread>
#include <vector>

#include <gmock/gmock.h>

namespace {

// A trivial implementation of CountingIncluder's virtual methods, so tests can
// instantiate.
class ConcreteCountingIncluder : public shaderc_util::CountingIncluder {
public:
virtual glslang::TShader::Includer::IncludeResult* include_delegate(
using IncludeResult = glslang::TShader::Includer::IncludeResult;
~ConcreteCountingIncluder() {
// Avoid leaks.
for (auto result : results_) {
release_delegate(result);
}
}
virtual IncludeResult* include_delegate(
const char* requested, const char* requestor, IncludeType,
size_t) override {
const char kError[] = "Unexpected #include";
return new glslang::TShader::Includer::IncludeResult{
"", kError, strlen(kError), nullptr};
results_.push_back(new IncludeResult{"", kError, strlen(kError), nullptr});
return results_.back();
}
virtual void release_delegate(
glslang::TShader::Includer::IncludeResult* include_result) override {
virtual void release_delegate(IncludeResult* include_result) override {
delete include_result;
}

private:
// All the results we've returned so far.
std::vector<IncludeResult*> results_;
};

TEST(CountingIncluderTest, InitialCount) {
Expand Down

0 comments on commit dcb3036

Please sign in to comment.