Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: include/core/SkTemplates.h

Issue 18915010: Fix leak in SkAutoSTArray (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fixed compiler complaint r.e. ">>" vs. "> >" for templates Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/UtilsTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkTemplates_DEFINED 10 #ifndef SkTemplates_DEFINED
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 250
251 /** Destroys previous objects in the array and default constructs count numb er of objects */ 251 /** Destroys previous objects in the array and default constructs count numb er of objects */
252 void reset(size_t count) { 252 void reset(size_t count) {
253 T* start = fArray; 253 T* start = fArray;
254 T* iter = start + fCount; 254 T* iter = start + fCount;
255 while (iter > start) { 255 while (iter > start) {
256 (--iter)->~T(); 256 (--iter)->~T();
257 } 257 }
258 258
259 if (fCount != count) { 259 if (fCount != count) {
260 if (count > N) { 260 if (fCount > N) {
261 // 'fArray' was allocated last time so free it now
reed1 2013/07/12 18:23:35 possibly also SkASSERT(fStorage != fArray);
robertphillips 2013/07/12 18:44:43 Done.
261 sk_free(fArray); 262 sk_free(fArray);
262 } 263 }
263 264
264 if (count > N) { 265 if (count > N) {
265 fArray = (T*) sk_malloc_throw(count * sizeof(T)); 266 fArray = (T*) sk_malloc_throw(count * sizeof(T));
266 } else if (count > 0) { 267 } else if (count > 0) {
267 fArray = (T*) fStorage; 268 fArray = (T*) fStorage;
268 } else { 269 } else {
269 fArray = NULL; 270 fArray = NULL;
270 return;
271 } 271 }
272 272
273 fCount = count; 273 fCount = count;
274 } 274 }
275 275
276 iter = fArray; 276 iter = fArray;
277 T* stop = fArray + count; 277 T* stop = fArray + count;
278 while (iter < stop) { 278 while (iter < stop) {
279 SkNEW_PLACEMENT(iter++, T); 279 SkNEW_PLACEMENT(iter++, T);
280 } 280 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 /** 454 /**
455 * Returns void* because this object does not initialize the 455 * Returns void* because this object does not initialize the
456 * memory. Use placement new for types that require a cons. 456 * memory. Use placement new for types that require a cons.
457 */ 457 */
458 void* get() { return fStorage.get(); } 458 void* get() { return fStorage.get(); }
459 private: 459 private:
460 SkAlignedSStorage<sizeof(T)*N> fStorage; 460 SkAlignedSStorage<sizeof(T)*N> fStorage;
461 }; 461 };
462 462
463 #endif 463 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/UtilsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698