aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar junov@google.com <junov@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-05-25 20:26:11 +0000
committerGravatar junov@google.com <junov@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-05-25 20:26:11 +0000
commit5d6e108624ee27f9cf6b10a77db2046cb29dc6cc (patch)
treeb13a4c84761d9088f5849dfc111b178be5878e47
parentd9097e0256bf7c778cba0438fb1a1ee65b1b78f5 (diff)
This change eliminates a potential memory leak and it
fixes a mem check bug that was blocking the skia roll into Chromium. BUG=http://code.google.com/p/skia/issues/detail?id=278 git-svn-id: http://skia.googlecode.com/svn/trunk@1424 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gpu/src/GrBinHashKey.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/gpu/src/GrBinHashKey.h b/gpu/src/GrBinHashKey.h
index 683528b61e..a270cc2891 100644
--- a/gpu/src/GrBinHashKey.h
+++ b/gpu/src/GrBinHashKey.h
@@ -84,8 +84,8 @@ private:
public:
void copyAndTakeOwnership(GrBinHashKey<Entry, StackSize>& key) {
- memcpy(this, &key, sizeof(*this));
GrAssert(key.fIsValid);
+ copyFields(key);
if (fUseHeap) {
key.fHeapData = NULL; // ownership transfer
}
@@ -98,7 +98,7 @@ public:
void deepCopyFrom(const GrBinHashKey<Entry, StackSize>& key) {
GrAssert(key.fIsValid);
- memcpy(this, &key, sizeof(key));
+ copyFields(key);
if (fUseHeap) {
fHeapData = reinterpret_cast<uint8_t*>(
GrMalloc(sizeof(uint8_t) * fPhysicalSize));
@@ -197,6 +197,22 @@ public:
}
private:
+ void copyFields(const GrBinHashKey<Entry, StackSize>& src) {
+ if (fUseHeap) {
+ GrFree(fHeapData);
+ }
+ // We do a field-by-field copy because this is a non-POD
+ // class, and therefore memcpy would be bad
+ fA = src.fA;
+ fB = src.fB;
+ fLength = src.fLength;
+ memcpy(fStackData, src.fStackData, StackSize);
+ fHeapData = src.fHeapData;
+ fPhysicalSize = src.fPhysicalSize;
+ fUseHeap = src.fUseHeap;
+ fPass = src.fPass;
+ }
+
// For computing the Adler-32 hash
enum Constants {
kBigPrime = 65521 // largest prime smaller than 2^16