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

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: Fix the assert 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 /** Destroys previous objects in the array and default constructs count numb er of objects */ 244 /** Destroys previous objects in the array and default constructs count numb er of objects */
245 void reset(size_t count) { 245 void reset(size_t count) {
246 T* start = fArray; 246 T* start = fArray;
247 T* iter = start + fCount; 247 T* iter = start + fCount;
248 while (iter > start) { 248 while (iter > start) {
249 (--iter)->~T(); 249 (--iter)->~T();
250 } 250 }
251 251
252 if (fCount != count) { 252 if (fCount != count) {
253 if (count > N) { 253 if (fCount > N) {
254 // 'fArray' was allocated last time so free it now
255 SkASSERT((T*) fStorage != fArray);
254 sk_free(fArray); 256 sk_free(fArray);
255 } 257 }
256 258
257 if (count > N) { 259 if (count > N) {
258 fArray = (T*) sk_malloc_throw(count * sizeof(T)); 260 fArray = (T*) sk_malloc_throw(count * sizeof(T));
259 } else if (count > 0) { 261 } else if (count > 0) {
260 fArray = (T*) fStorage; 262 fArray = (T*) fStorage;
261 } else { 263 } else {
262 fArray = NULL; 264 fArray = NULL;
263 return;
264 } 265 }
265 266
266 fCount = count; 267 fCount = count;
267 } 268 }
268 269
269 iter = fArray; 270 iter = fArray;
270 T* stop = fArray + count; 271 T* stop = fArray + count;
271 while (iter < stop) { 272 while (iter < stop) {
272 SkNEW_PLACEMENT(iter++, T); 273 SkNEW_PLACEMENT(iter++, T);
273 } 274 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 /** 448 /**
448 * Returns void* because this object does not initialize the 449 * Returns void* because this object does not initialize the
449 * memory. Use placement new for types that require a cons. 450 * memory. Use placement new for types that require a cons.
450 */ 451 */
451 void* get() { return fStorage.get(); } 452 void* get() { return fStorage.get(); }
452 private: 453 private:
453 SkAlignedSStorage<sizeof(T)*N> fStorage; 454 SkAlignedSStorage<sizeof(T)*N> fStorage;
454 }; 455 };
455 456
456 #endif 457 #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