With the most annoying memory leak found by Derek Buitenhuis.
Unified · Split
| @@ -18,6 +18,7 @@ · 17 unmodified lines | ||
| 18 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | +#include "error.h" | |
| 21 | 22 | #include "log.h" |
| 22 | 23 | #include "mem.h" |
| 23 | 24 | #include "tree.h" |
| @@ -211,32 +212,50 @@ static int cmp(void *a, const void *b) · 187 unmodified lines | ||
| 211 | 212 | int main(void) |
| 212 | 213 | { |
| 213 | 214 | int i; |
| 214 | − void *k; | |
| 215 | 215 | AVTreeNode *root = NULL, *node = NULL; |
| 216 | 216 | AVLFG prng; |
| 217 | 217 | |
| 218 | 218 | av_lfg_init(&prng, 1); |
| 219 | 219 | |
| 220 | 220 | for (i = 0; i < 10000; i++) { |
| 221 | − int j = av_lfg_get(&prng) % 86294; | |
| 221 | + AVTreeNode *node2 = NULL; | |
| 222 | + intptr_t j = av_lfg_get(&prng) % 86294; | |
| 223 | + void *ret, *jj = (void *)(j + 1); | |
| 224 | + | |
| 225 | + while (ret = av_tree_find(root, jj, cmp, NULL)) { | |
| 226 | + j = av_lfg_get(&prng) % 86294; | |
| 227 | + jj = (void *)(j + 1); | |
| 228 | + } | |
| 229 | + | |
| 222 | 230 | if (check(root) > 999) { |
| 223 | 231 | av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); |
| 224 | 232 | print(root, 0); |
| 225 | 233 | return -1; |
| 226 | 234 | } |
| 235 | + | |
| 227 | 236 | if (!node) |
| 228 | 237 | node = av_tree_node_alloc(); |
| 229 | − av_tree_insert(&root, (void *)(j + 1), cmp, &node); | |
| 230 | − | |
| 231 | − j = av_lfg_get(&prng) % 86294; | |
| 232 | − { | |
| 233 | − AVTreeNode *node2 = NULL; | |
| 234 | − av_tree_insert(&root, (void *)(j + 1), cmp, &node2); | |
| 235 | − k = av_tree_find(root, (void *)(j + 1), cmp, NULL); | |
| 236 | − if (k) | |
| 237 | − av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); | |
| 238 | + if (!node) { | |
| 239 | + av_log(NULL, AV_LOG_ERROR, "Memory allocation failure.\n"); | |
| 240 | + return AVERROR(ENOMEM); | |
| 238 | 241 | } |
| 242 | + av_tree_insert(&root, jj, cmp, &node); | |
| 243 | + | |
| 244 | + while (ret = av_tree_find(root, jj, cmp, NULL)) { | |
| 245 | + j = av_lfg_get(&prng) % 86294; | |
| 246 | + jj = (void *)(j + 1); | |
| 247 | + } | |
| 248 | + | |
| 249 | + ret = av_tree_insert(&root, jj, cmp, &node2); | |
| 250 | + if (ret != jj) | |
| 251 | + av_tree_destroy(node2); | |
| 252 | + ret = av_tree_find(root, jj, cmp, NULL); | |
| 253 | + if (ret) | |
| 254 | + av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); | |
| 239 | 255 | } |
| 256 | + | |
| 257 | + av_tree_destroy(root); | |
| 258 | + | |
| 240 | 259 | return 0; |
| 241 | 260 | } |
| 242 | 261 | #endif |