 +
 +			if (chapter_stack_depth == 0)
 +			{
++				fz_try(ctx)
++				{
++					outline = fz_new_outline(ctx);
++				}
++				fz_catch(ctx)
++				{
++					fz_drop_outline(ctx, outline);
++					fz_rethrow(ctx);
++				}
 +				chapter_stack[0] = outline;
 +				chapter_stack_depth = 1;
 +				current_chapter = outline;

+cbz_load_outline(fz_context *ctx, fz_document *doc_)
+{
+	cbz_document *doc = (cbz_document *) doc_;
+	fz_outline *outline = fz_new_outline(ctx);
+	size_t max_chapter_stack_depth = 10;
+	fz_outline *chapter_stack[max_chapter_stack_depth];
+	size_t chapter_stack_depth = 0;

 static fz_document *
 cbz_open_document_with_stream(fz_context *ctx, fz_stream *file)
 {
@@ -246,6 +349,7 @@ cbz_open_document_with_stream(fz_context *ctx, fz_stream *file)
 	doc->super.lookup_metadata = cbz_lookup_metadata;
 	doc->super.needs_password = cbz_needs_password;
 	doc->super.authenticate_password = cbz_authenticate_password;
