firebase / firebase/firebase-cpp-sdk

[Bug] MemoryLeak

Open
#1,446 0 comments 0 reactions 0 assignees View on GitHub
api: core new type: question
Dominant language
C++
Stars
326
Forks
137
Avg merge
3d 9h
Merged PRs (30d)
5

Description

* Pre-built SDK from the https://github.com/firebase/firebase-cpp-sdk/releases/tag/v11.4.0
* Firebase C++ SDK version: 11.4.0
* Problematic Firebase Component: App
* Platform you are using the C++ SDK on: Windows
* Platform you are targeting: Windows desktop

If you will run this code from MSVC you will see memory leaks report in the output console:

Source Code:

```
#define _CRTDBG_MAP_ALLOC
#include
#include

#include
#include
#include
#include

#include

#include
#include
#include
#include

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdLine, int nCmdShow)
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF/* | _CRTDBG_CHECK_ALWAYS_DF*/);

FILE* f = fopen("google-services.json", "r");
assert(f);
fseek(f, 0, SEEK_END);
auto size = ftell(f);
fseek(f, 0, SEEK_SET);
std::string json;
json.resize(size);
fread(&json[0], 1, size, f);
fclose(f);

::firebase::AppOptions ao;
::firebase::AppOptions::LoadFromJsonConfig(json.data(), &ao);

auto app = ::firebase::App::Create(ao);
// auto rc = ::firebase::remote_config::RemoteConfig::GetInstance(app);
auto db = ::firebase::database::Database::GetInstance(app);

std::this_thread::sleep_for(std::chrono::seconds(1));

delete app;

return 0;
}

```
Here is CMakeLists.txt:

```
cmake_minimum_required(VERSION 3.22)

project(FireBaseTest LANGUAGES CXX)

add_executable(${PROJECT_NAME} WIN32 test.cpp)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")

set(MSVC_RUNTIME_MODE "MD")
add_subdirectory("../libs/firebase_cpp_sdk" "${CMAKE_CURRENT_BINARY_DIR}/firebase_cpp_sdk")
set(CMAKE_BUILD_TYPE "")
target_link_libraries(${PROJECT_NAME}
firebase_app
firebase_database
firebase_remote_config
)

target_link_libraries(${PROJECT_NAME}
ws2_32.lib
psapi.lib
iphlpapi.lib
userenv.lib
crypt32.lib
)

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.