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

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: 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 | no next file » | 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
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 return;
reed1 2013/07/12 14:48:45 Eeek! If we get here, seems like we will not have
271 } 272 }
272 273
273 fCount = count; 274 fCount = count;
274 } 275 }
275 276
276 iter = fArray; 277 iter = fArray;
277 T* stop = fArray + count; 278 T* stop = fArray + count;
278 while (iter < stop) { 279 while (iter < stop) {
279 SkNEW_PLACEMENT(iter++, T); 280 SkNEW_PLACEMENT(iter++, T);
280 } 281 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 /** 455 /**
455 * Returns void* because this object does not initialize the 456 * Returns void* because this object does not initialize the
456 * memory. Use placement new for types that require a cons. 457 * memory. Use placement new for types that require a cons.
457 */ 458 */
458 void* get() { return fStorage.get(); } 459 void* get() { return fStorage.get(); }
459 private: 460 private:
460 SkAlignedSStorage<sizeof(T)*N> fStorage; 461 SkAlignedSStorage<sizeof(T)*N> fStorage;
461 }; 462 };
462 463
463 #endif 464 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698