memory leaks, use vcpkg mupdf

This commit is contained in:
simon987 2020-04-05 20:06:41 -04:00
parent 842681a0a9
commit 22723f900b
6 changed files with 17 additions and 33 deletions

View File

@ -29,7 +29,7 @@ find_package(lz4 REQUIRED)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
find_package(Tesseract CONFIG REQUIRED) find_package(Tesseract CONFIG REQUIRED)
find_package(harfbuzz CONFIG REQUIRED) find_library(HARFBUZZ_LIBRARIES harfbuzz)
find_package(OpenJPEG CONFIG REQUIRED) find_package(OpenJPEG CONFIG REQUIRED)
find_package(JPEG REQUIRED) find_package(JPEG REQUIRED)
find_package(LibXml2 REQUIRED) find_package(LibXml2 REQUIRED)
@ -37,29 +37,8 @@ find_package(FFMPEG REQUIRED)
#find_package(OpenSSL REQUIRED) #find_package(OpenSSL REQUIRED)
find_package(LibLZMA REQUIRED) find_package(LibLZMA REQUIRED)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
find_package(freetype CONFIG REQUIRED)
find_library(JBIG2DEC_LIB NAMES jbig2decd jbig2dec)
include(ExternalProject)
find_program(MAKE_EXE NAMES gmake nmake make)
set(MUPDF_CFLAGS "-fPIC -DFZ_ENABLE_JS=0 -DFZ_ENABLE_ICC=0")
ExternalProject_Add(
mupdf
# TODO: use master branch ?
URL https://mupdf.com/downloads/archive/mupdf-1.16.1-source.tar.xz
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
PREFIX "third-party/ext_mupdf"
BINARY_DIR "third-party/ext_mupdf/src/mupdf"
BUILD_COMMAND export CFLAGS=${MUPDF_CFLAGS} && HAVE_CURL=no HAVE_GLUT=no USE_SYSTEM_LIBJPEG=yes ${MAKE_EXE} -j 3 --silent
)
SET(MUPDF_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/ext_mupdf/src/mupdf/build/release/)
SET(MUPDF_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/ext_mupdf/src/mupdf/include/)
target_compile_options( target_compile_options(
@ -69,11 +48,6 @@ target_compile_options(
-g -g
) )
add_dependencies(
scan
mupdf
)
SET(CMAKE_C_LINK_EXECUTABLE "g++ <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") SET(CMAKE_C_LINK_EXECUTABLE "g++ <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
string(REGEX REPLACE "-lvdpau" "" FFMPEG_LIBRARIES "${FFMPEG_LIBRARIES}") string(REGEX REPLACE "-lvdpau" "" FFMPEG_LIBRARIES "${FFMPEG_LIBRARIES}")
@ -90,8 +64,12 @@ target_link_libraries(
lzo2 lzo2
LibLZMA::LibLZMA LibLZMA::LibLZMA
freetype ${HARFBUZZ_LIBRARIES}
libmupdf
freetype
${HARFBUZZ_LIBRARIES}
${JBIG2DEC_LIB}
# OpenSSL::SSL OpenSSL::Crypto # OpenSSL::SSL OpenSSL::Crypto
stdc++ stdc++
@ -100,9 +78,6 @@ target_link_libraries(
m m
-Wl,--no-whole-archive -Wl,--no-whole-archive
"${MUPDF_LIB_DIR}/libmupdf.a"
"${MUPDF_LIB_DIR}/libmupdf-third.a"
${JPEG_LIBRARIES} ${JPEG_LIBRARIES}
${Tesseract_LIBRARIES} ${Tesseract_LIBRARIES}
${LIBXML2_LIBRARIES} ${LIBXML2_LIBRARIES}

View File

@ -327,4 +327,5 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, docum
size_t buf_len; size_t buf_len;
void * buf = read_all(f, &buf_len); void * buf = read_all(f, &buf_len);
parse_ebook_mem(ctx, buf, buf_len, mime_str, doc); parse_ebook_mem(ctx, buf, buf_len, mime_str, doc);
free(buf);
} }

View File

@ -424,3 +424,7 @@ void parse_media(scan_media_ctx_t *ctx, vfile_t *f, document_t *doc) {
parse_media_vfile(ctx, f, doc); parse_media_vfile(ctx, f, doc);
} }
} }
void init_media() {
av_log_set_level(AV_LOG_QUIET);
}

View File

@ -15,5 +15,6 @@ typedef struct {
} scan_media_ctx_t; } scan_media_ctx_t;
void parse_media(scan_media_ctx_t *ctx, vfile_t *f, document_t *doc); void parse_media(scan_media_ctx_t *ctx, vfile_t *f, document_t *doc);
void init_media();
#endif #endif

View File

@ -106,6 +106,7 @@ void parse_ooxml(scan_ooxml_ctx_t *ctx, vfile_t *f, document_t *doc) {
if (ret != ARCHIVE_OK) { if (ret != ARCHIVE_OK) {
CTX_LOG_ERRORF(doc->filepath, "Could not read archive: %s", archive_error_string(a)) CTX_LOG_ERRORF(doc->filepath, "Could not read archive: %s", archive_error_string(a))
archive_read_free(a); archive_read_free(a);
free(buf);
return; return;
} }
@ -137,4 +138,5 @@ void parse_ooxml(scan_ooxml_ctx_t *ctx, vfile_t *f, document_t *doc) {
archive_read_close(a); archive_read_close(a);
archive_read_free(a); archive_read_free(a);
text_buffer_destroy(&tex); text_buffer_destroy(&tex);
free(buf);
} }

View File

@ -8,6 +8,7 @@ scan_code_t parse_text(scan_text_ctx_t *ctx, struct vfile *f, document_t *doc) {
int ret = f->read(f, buf, to_read); int ret = f->read(f, buf, to_read);
if (ret < 0) { if (ret < 0) {
CTX_LOG_ERRORF(doc->filepath, "read() returned error code: [%d]", ret) CTX_LOG_ERRORF(doc->filepath, "read() returned error code: [%d]", ret)
free(buf);
return SCAN_ERR_READ; return SCAN_ERR_READ;
} }