Skip to content

valgrind reports about leak memory #1443

Closed
@DrakonST88

Description

@DrakonST88

Describe the bug

==13247== Memcheck, a memory error detector
==13247== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13247== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==13247== Command: ./test_json
==13247== Parent PID: 1132
==13247== 
==13247== 
==13247== HEAP SUMMARY:
==13247==     in use at exit: 40 bytes in 1 blocks
==13247==   total heap usage: 57 allocs, 56 frees, 93,478 bytes allocated
==13247== 
==13247== 40 bytes in 1 blocks are still reachable in loss record 1 of 1
==13247==    at 0x483BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==13247==    by 0x486B8D1: Json::Value::nullSingleton() (in /usr/lib/x86_64-linux-gnu/libjsoncpp.so.1.7.4)
==13247==    by 0x485F93C: ??? (in /usr/lib/x86_64-linux-gnu/libjsoncpp.so.1.7.4)
==13247==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==13247==    by 0x4011CA0: call_init (dl-init.c:30)
==13247==    by 0x4011CA0: _dl_init (dl-init.c:119)
==13247==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==13247== 
==13247== LEAK SUMMARY:
==13247==    definitely lost: 0 bytes in 0 blocks
==13247==    indirectly lost: 0 bytes in 0 blocks
==13247==      possibly lost: 0 bytes in 0 blocks
==13247==    still reachable: 40 bytes in 1 blocks
==13247==         suppressed: 0 bytes in 0 blocks
==13247== 
==13247== For lists of detected and suppressed errors, rerun with: -s
==13247== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

To Reproduce
Steps to reproduce the behavior:

  1. Compile:
    test_json.cc
include <cstdlib>
#include <fstream>
#include <iostream>
#include <ctime>
#include <fstream>
#include <jsoncpp/json/json.h>

int main(int argc, char *argv[])
{
    Json::Value _json;
    Json::StyledStreamWriter writer_jsonf;
    Json::FastWriter writer_json;
    std::ofstream outFile;

    // Data for json
    std::string name = "MyTest";
    int host = 2;
    int core = 5;

    _json[name]["timestamp"] = Json::Value::UInt64(time(nullptr));
    _json[name]["host"] = Json::Value(host);
    _json[name]["core"] = Json::Value(core);

    std::cout << "=> _json:\n" << _json << std::endl;

    // Write the output to a file
    outFile.open("output.jsonf");
    writer_jsonf.write(outFile, _json);
    outFile.close();

    // Write the output to a file as single line
    outFile.open("output.json");
    outFile << writer_json.write(_json);
    outFile.close();

    return 0;
}

Makefile

CPPFLAGS = -fdiagnostics-color=always -g3 -O0 -Wall -std=c++17
LDFLAGS =
LDLIBS = -ljsoncpp

APP := test_json

.PHONY: all clean

all:
    $(CXX) $(CPPFLAGS) $(LDFLAGS) $(APP).cc $(LDLIBS) -o $(APP)

clean:
    rm -f $(APP) output.json*
  1. Run:
    valgrind --leak-check=full --show-leak-kinds=all --show-reachable=yes --log-file=rslt.log ./test_json

Expected behavior
No leak memory

Desktop (please complete the following information):
Linux 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions