Make sure we correctly copy caches keys.
Bug #5136067

Change-Id: I366e840bef44415436dc7b13d89cfb610feed663
diff --git a/libs/hwui/GradientCache.h b/libs/hwui/GradientCache.h
index 45c1005..7339853 100644
--- a/libs/hwui/GradientCache.h
+++ b/libs/hwui/GradientCache.h
@@ -38,28 +38,27 @@
 
     GradientCacheEntry(uint32_t* colors, float* positions, int count,
             SkShader::TileMode tileMode) {
-        this->count = count;
-        this->colors = new uint32_t[count];
-        this->positions = new float[count];
-        this->tileMode = tileMode;
-
-        memcpy(this->colors, colors, count * sizeof(uint32_t));
-        memcpy(this->positions, positions, count * sizeof(float));
+        copy(colors, positions, count, tileMode);
     }
 
     GradientCacheEntry(const GradientCacheEntry& entry) {
-        this->count = entry.count;
-        this->colors = new uint32_t[count];
-        this->positions = new float[count];
-        this->tileMode = entry.tileMode;
-
-        memcpy(this->colors, entry.colors, count * sizeof(uint32_t));
-        memcpy(this->positions, entry.positions, count * sizeof(float));
+        copy(entry.colors, entry.positions, entry.count, entry.tileMode);
     }
 
     ~GradientCacheEntry() {
-        if (colors) delete[] colors;
-        if (positions) delete[] positions;
+        delete[] colors;
+        delete[] positions;
+    }
+
+    GradientCacheEntry& operator=(const GradientCacheEntry& entry) {
+        if (this != &entry) {
+            delete[] colors;
+            delete[] positions;
+
+            copy(entry.colors, entry.positions, entry.count, entry.tileMode);
+        }
+
+        return *this;
     }
 
     bool operator<(const GradientCacheEntry& r) const {
@@ -82,6 +81,18 @@
     int count;
     SkShader::TileMode tileMode;
 
+private:
+
+    void copy(uint32_t* colors, float* positions, int count, SkShader::TileMode tileMode) {
+        this->count = count;
+        this->colors = new uint32_t[count];
+        this->positions = new float[count];
+        this->tileMode = tileMode;
+
+        memcpy(this->colors, colors, count * sizeof(uint32_t));
+        memcpy(this->positions, positions, count * sizeof(float));
+    }
+
 }; // GradientCacheEntry
 
 /**