Skip to content

[Bug] MemoryLeak #1446

Open
Open
@DaveBy

Description

@DaveBy

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 <crtdbg.h>
#include <stdlib.h>

#include <stdio.h>
#include <string>
#include <assert.h>
#include <thread>

#include <Windows.h>

#include <firebase/app.h>
#include <firebase/remote_config.h>
#include <firebase/database.h>
#include <firebase/database/database_reference.h>

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
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions