Differences From Artifact [8eda9d8f37]:
- File src/OFSecureData.m — part of check-in [8be102635a] at 2020-10-25 23:55:42 on branch trunk — OFSecureData: Fix memory leak on error (user: js, size: 14726) [annotate] [blame] [check-ins using]
To Artifact [de9178b4e4]:
- File
src/OFSecureData.m
— part of check-in
[3d8286feee]
at
2020-11-04 23:18:25
on branch trunk
— Remove of_free()
While it makes sense to wrap malloc and calloc to replace the error
checking with exceptions, it does not make sense to wrap free. (user: js, size: 14705) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
124 125 126 127 128 129 130 | OF_ENSURE(of_tlskey_set(numPreallocatedPagesKey, (void *)numPreallocatedPages)); # endif page = preallocatedPages[numPreallocatedPages]; if (numPreallocatedPages == 0) { | | | | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | OF_ENSURE(of_tlskey_set(numPreallocatedPagesKey, (void *)numPreallocatedPages)); # endif page = preallocatedPages[numPreallocatedPages]; if (numPreallocatedPages == 0) { free(preallocatedPages); preallocatedPages = NULL; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(of_tlskey_set(preallocatedPagesKey, preallocatedPages)); # endif } return page; } } page = of_malloc(1, sizeof(*page)); @try { page->map = of_calloc(1, mapSize); } @catch (id e) { free(page); @throw e; } @try { page->page = mapPages(1); } @catch (id e) { free(page->map); 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 |
︙ | ︙ | |||
189 190 191 192 193 194 195 | size_t mapSize = OF_ROUND_UP_POW2(8, pageSize / CHUNK_SIZE) / 8; for (size_t i = 0; i < mapSize; i++) if (map[i] != 0) return; unmapPages(page->page, 1); | | | | 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | size_t mapSize = OF_ROUND_UP_POW2(8, pageSize / CHUNK_SIZE) / 8; for (size_t i = 0; i < mapSize; i++) if (map[i] != 0) return; unmapPages(page->page, 1); free(page->map); if (page->previous != NULL) page->previous->next = page->next; if (page->next != NULL) page->next->previous = page->previous; # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) if (firstPage == page) firstPage = page->next; if (lastPage == page) lastPage = page->previous; # else if (of_tlskey_get(firstPageKey) == page) OF_ENSURE(of_tlskey_set(firstPageKey, page->next)); if (of_tlskey_get(lastPageKey) == page) OF_ENSURE(of_tlskey_set(lastPageKey, page->previous)); # endif free(page); } static void * allocateMemory(struct page *page, size_t bytes) { size_t chunks, chunksLeft, pageSize, i, firstChunk; |
︙ | ︙ | |||
302 303 304 305 306 307 308 | @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]); | | | 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | @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]); free(preallocatedPages); preallocatedPages = NULL; @throw e; } numPreallocatedPages = numPages; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) |
︙ | ︙ |