Skip to content

Commit

Permalink
Fix code after refactoring (missing cleanup logic)
Browse files Browse the repository at this point in the history
  • Loading branch information
plzombie committed May 8, 2023
1 parent cf77022 commit 45a0144
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/depress_maker.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef struct {
typedef struct {
int (* convert_ctx)(void *ctx, size_t id, depress_flags_type flags, depress_load_image_type load_image, void *load_image_ctx);
bool (* merge_ctx)(void* ctx, size_t id);
void (* cleanup_ctx)(void *ctx, size_t id);
bool (* finalize_ctx)(void* ctx, depress_maker_finalize_type finalize);
void (* free_ctx)(void *ctx);
} depress_maker_type;
Expand Down
1 change: 1 addition & 0 deletions include/depress_maker_djvu.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef struct {

extern int depressMakerDjvuConvertCtx(void *ctx, size_t id, depress_flags_type flags, depress_load_image_type load_image, void *load_image_ctx);
extern bool depressMakerDjvuMergeCtx(void *ctx, size_t id);
extern void depressMakerDjvuCleanupCtx(void *ctx, size_t id);
extern bool depressMakerDjvuFinalizeCtx(void *ctx, const depress_maker_finalize_type finalize);
extern void depressMakerDjvuFreeCtx(void *ctx);

Expand Down
5 changes: 5 additions & 0 deletions src/depress_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bool depressDocumentInitDjvu(depress_document_type *document, depress_document_f
memset(&djvu, 0, sizeof(depress_maker_type));
djvu.convert_ctx = depressMakerDjvuConvertCtx;
djvu.merge_ctx = depressMakerDjvuMergeCtx;
djvu.cleanup_ctx = depressMakerDjvuCleanupCtx;
djvu.finalize_ctx = depressMakerDjvuFinalizeCtx;
djvu.free_ctx = depressMakerDjvuFreeCtx;

Expand All @@ -115,6 +116,8 @@ bool depressDocumentDestroy(depress_document_type *document)
if(!document->is_init) return false;

document->maker.free_ctx(document->maker_ctx);
memset(&(document->maker), 0, sizeof(depress_maker_type));
document->maker_ctx = 0;

if(document->tasks) {
depressDestroyTasks(document->tasks, document->tasks_num);
Expand Down Expand Up @@ -286,6 +289,8 @@ int depressDocumentProcessTasks(depress_document_type *document)
} else
InterlockedExchangePtr((uintptr_t *)(&document->tasks_processed), filecount);
}
if(filecount > 0)
document->maker.cleanup_ctx(document->maker_ctx, filecount);
}
}

Expand Down
23 changes: 18 additions & 5 deletions src/depress_maker_djvu.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,32 @@ bool depressMakerDjvuMergeCtx(void *ctx, size_t id)

if(depressSpawn(djvu_ctx->djvulibre_paths.djvm_path, arg0, true, true) == DEPRESS_INVALID_PROCESS_HANDLE)
result = false;


free(arg0);
}

return result;
}

void depressMakerDjvuCleanupCtx(void *ctx, size_t id)
{
depress_maker_djvu_ctx_type* djvu_ctx;

djvu_ctx = (depress_maker_djvu_ctx_type*)ctx;

if(id > 0) {
wchar_t page_file[32768];

swprintf(page_file, 32768, L"%ls/temp%llu.djvu", djvu_ctx->temp_path, (unsigned long long)id);

if(!_waccess(page_file, 06))
if(_wremove(page_file) == -1)
#if defined(_WIN32)
Sleep(0);
#else
usleep(1000);
#endif

free(arg0);
}

return result;
}

static void depressDocumentGetTitle(wchar_t *wtitle, char *title, bool use_short_name)
Expand Down

0 comments on commit 45a0144

Please sign in to comment.