Skip to content

Commit

Permalink
fix: address a potential memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
diamante0018 committed Apr 1, 2024
1 parent f3adaf4 commit b08d201
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[submodule "deps/curl"]
path = deps/curl
url = https://github.com/curl/curl.git
branch = curl-8_5_0
branch = curl-8_7_1
[submodule "deps/rapidjson"]
path = deps/rapidjson
url = https://github.com/Tencent/rapidjson.git
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ This is the tool we use to pull changes made from the release page of some of ou
- Install [Premake5][premake5-link] and add it to your system PATH
- Clone this repository using [Git][git-link]
- Update the submodules using ``git submodule update --init --recursive``
- Run Premake with either of these two options ``premake5 vs2022`` (Windows) or ``premake5 gmake2`` (Linux/macOS)
- Run Premake with either of these two options ``premake5 vs2022`` (for Windows) or ``premake5 gmake2`` (for Linux/macOS)
- On Windows, build the project via the solution file in ``build\aw-installer.sln``
- On Linux/macOS, build the project using [Make][make-link] via the ``Makefile`` located in the ``build`` folder

**IMPORTANT**
Requirements for Unix systems:
- Compilation: Please use Clang as the preferred compiler
- Dependencies: Ensure the LLVM C++ Standard library is installed
- Compilation: Please use Clang
- Dependencies: Ensure the LLVM [C++ Standard library][libcxx-link] is installed
- Alternative compilers: If you opt for a different compiler such as GCC, use the [Mold][mold-link] linker
- Customization: Modifications to the Premake5.lua script may be required
- Platform support: Details regarding supported platforms are available in [build.yml](.github/workflows/build.yml)

[premake5-link]: https://premake.github.io
[git-link]: https://git-scm.com
[make-link]: https://en.wikipedia.org/wiki/Make_(software)
[libcxx-link]: https://libcxx.llvm.org/
[mold-link]: https://github.com/rui314/mold
2 changes: 1 addition & 1 deletion deps/curl
Submodule curl updated 2131 files
13 changes: 9 additions & 4 deletions src/utils/compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ namespace utils::compression

z_stream& get()
{
return stream_; //
return stream_;
}

bool is_valid() const
[[nodiscard]] bool is_valid() const
{
return valid_;
}
Expand Down Expand Up @@ -177,7 +177,7 @@ namespace utils::compression
}

// I apologize for writing such a huge function
// I'm Using make_preferred() so / are converted to \\ on Windows but not on POSIX
// I'm using make_preferred() so / are converted to \\ on Windows but not on POSIX
void archive::decompress(const std::string& filename, const std::filesystem::path& out_dir)
{
unzFile file = unzOpen(filename.c_str());
Expand Down Expand Up @@ -229,7 +229,7 @@ namespace utils::compression
// Entry is a file. Extract it.
if (unzOpenCurrentFile(file) != UNZ_OK)
{
// Could not read file from the ZIP
unzClose(file);
throw std::runtime_error(string::va("Failed to read file \"%s\" from \"%s\"", out_file.c_str(), filename.c_str()));
}

Expand All @@ -243,6 +243,8 @@ namespace utils::compression
std::ofstream out(path.make_preferred().string(), std::ios::binary | std::ios::trunc);
if (!out.is_open())
{
unzCloseCurrentFile(file);
unzClose(file);
throw std::runtime_error("Failed to open stream");
}

Expand All @@ -252,6 +254,8 @@ namespace utils::compression
read_bytes = unzReadCurrentFile(file, read_buffer, READ_BUFFER_SIZE);
if (read_bytes < 0)
{
unzCloseCurrentFile(file);
unzClose(file);
throw std::runtime_error(string::va("Error while reading \"%s\" from the archive", out_file.c_str()));
}

Expand All @@ -273,6 +277,7 @@ namespace utils::compression
// Go the the next entry listed in the ZIP file.
if ((i + 1) < global_info.number_entry)
{
// According to the AI overlords I do not need to close the file with unzCloseCurrentFile here
if (unzGoToNextFile(file) != UNZ_OK)
{
break;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace utils::io
{
bool remove_file(const std::string& file)
{
return remove(file.c_str()) == 0;
return std::remove(file.c_str()) == 0;
}

bool move_file(const std::string& src, const std::string& target)
{
return rename(src.c_str(), target.c_str()) == 0;
return std::rename(src.c_str(), target.c_str()) == 0;
}

bool file_exists(const std::string& file)
Expand Down

0 comments on commit b08d201

Please sign in to comment.