From 510d67359c9d79c2958414f2e959ff8baeab0dbb Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sat, 25 Apr 2015 15:26:50 +0200 Subject: [PATCH] Cleaned up code that loads a manual from an OPK file Most of it is for readability only, but there is also a leak that was plugged: opk_close() is now called if extraction fails. --- src/linkapp.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/linkapp.cpp b/src/linkapp.cpp index a804085..1b00909 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -414,28 +414,21 @@ void LinkApp::showManual() { #ifdef HAVE_LIBOPK if (isOPK) { - vector readme; - char *ptr; - struct OPK *opk; - int err; - void *buf; - size_t len; - - opk = opk_open(opkFile.c_str()); + struct OPK *opk = opk_open(opkFile.c_str()); if (!opk) { WARNING("Unable to open OPK to read manual\n"); return; } - err = opk_extract_file(opk, manual.c_str(), &buf, &len); + void *buf; + size_t len; + int err = opk_extract_file(opk, manual.c_str(), &buf, &len); + opk_close(opk); if (err < 0) { - WARNING("Unable to read manual from OPK\n"); + WARNING("Unable to extract manual from OPK\n"); return; } - opk_close(opk); - - ptr = (char *) buf; - string str(ptr, len); + string str((char *) buf, len); free(buf); if (manual.substr(manual.size()-8,8)==".man.txt") {