Index: src/OFSecureData.m ================================================================== --- src/OFSecureData.m +++ src/OFSecureData.m @@ -139,12 +139,23 @@ return page; } } page = of_malloc(1, sizeof(*page)); - page->map = of_calloc(1, mapSize); - page->page = mapPages(1); + @try { + page->map = of_calloc(1, mapSize); + } @catch (id e) { + of_free(page); + @throw e; + } + @try { + page->page = mapPages(1); + } @catch (id e) { + of_free(page->map); + of_free(page); + @throw e; + } of_explicit_memset(page->page, 0, pageSize); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) lastPage = of_tlskey_get(lastPageKey); # endif @@ -276,21 +287,32 @@ size_t numPages = OF_ROUND_UP_POW2(pageSize, size) / pageSize; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct page **preallocatedPages = of_tlskey_get(preallocatedPagesKey); size_t numPreallocatedPages; # endif + size_t i; if (preallocatedPages != NULL) @throw [OFInvalidArgumentException exception]; preallocatedPages = of_calloc(numPages, sizeof(struct page)); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) of_tlskey_set(preallocatedPagesKey, preallocatedPages); # endif - for (size_t i = 0; i < numPages; i++) - preallocatedPages[i] = addPage(false); + @try { + for (i = 0; i < numPages; i++) + preallocatedPages[i] = addPage(false); + } @catch (id e) { + for (size_t j = 0; j < i; j++) + removePageIfEmpty(preallocatedPages[j]); + + of_free(preallocatedPages); + preallocatedPages = NULL; + + @throw e; + } numPreallocatedPages = numPages; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) of_tlskey_set(numPreallocatedPagesKey, (void *)(uintptr_t)numPreallocatedPages);