Skip to content

json object's creation can freezes execution #231

Closed

Description

@cfoursan

When I try create json object and if no memory to allocate there is execution freeze instead of std::bad_alloc.

Gdb trace:
Thread 541 (Thread 0x7fc74f64a700 (LWP 133066)):
#0 0x000000000043cf71 in ZSt3getILm0EIPSt6vectorIN8nlohmann10basic_jsonISt3mapS0_SsblmdSaEESaIS4_EEZNS4_6createIS6_ISt16initializer_listIS4_EEEEPT_DpOT0_EUlS7_E_EENSt11__add_c_refINSt13tuple_elementIXT_ESt5tupleIIDpT0_EEE4typeEE4typeERKSM (__t=empty std::tuple) at /usr/include/c++/4.8/tuple:766
#1 0x000000000043cf9c in _ZNKSt10unique_ptrISt6vectorIN8nlohmann10basic_jsonISt3mapS0_SsblmdSaEESaIS4_EEZNS4_6createIS6_ISt16initializer_listIS4_EEEEPT_DpOT0_EUlPS6_E_E3getEv (this=0x7fc74f648ba0) at /usr/include/c++/4.8/bits/unique_ptr.h:234
#2 0x000000000043a1d1 in nlohmann::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator>::create<std::vector<nlohmann::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator>, std::allocator<nlohmann::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator> > >, std::initializer_list<nlohmann::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator> > >(std::initializer_list<nlohmann::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator> >&&) () at ../src/json.hpp:689
#3 0x0000000000437af4 in nlohmann::basic_json<std::map, std::vector, std::string, bool, long, unsigned long, double, std::allocator>::basic_json (this=0x7fc74f648f30, init=..., type_deduction=true, manual_type=nlohmann::basic_json<std::map, std::vector, std::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator>::array) at ../src/json.hpp:1571

Activity

  1. nlohmann commented on Apr 7, 2016

    @nlohmann
    Owner

    Hi @cfoursan, which OS and compiler are you using?

  2. cfoursan commented on Apr 7, 2016

    @cfoursan
    Author

    Hi. Sorry, forget about that information.
    g++ (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4
    Ubuntu 14.04.3 LTS, Trusty Tahr

  3. nlohmann commented on Apr 7, 2016

    @nlohmann
    Owner

    There are known issues with GCC 4.8's C++11 support (see https://github.com/nlohmann/json#supported-compilers). I am not sure whether this could be the reason for this issue, but could you try with a newer version?

  4. nlohmann commented on Apr 29, 2016

    @nlohmann
    Owner

    Hi @cfoursan, could you please check again with the most recent could (branch "develop")?

  5. added
    state: please discuss
    on Apr 29, 2016
  6. cfoursan commented on May 5, 2016

    @cfoursan
    Author

    Hi @nlohmann, I tried on
    g++ (Ubuntu 5.2.1-22ubuntu2) 5.2.1 20151010
    Ubuntu 15.10 (Wily Werewolf).

    I got std::bad_alloc as expected. So version of GCC could be a reason of this issue.

  7. nlohmann commented on May 11, 2016

    @nlohmann
    Owner

    I still cannot reproduce the error. Can you provide me with concrete code so I can try?

  8. nlohmann commented on May 25, 2016

    @nlohmann
    Owner

    @cfoursan Can you provide me with concrete code so I can try?

  9. nlohmann commented on May 28, 2016

    @nlohmann
    Owner

    Closed due to inactivity.

  10. cfoursan commented on May 29, 2016

    @cfoursan
    Author

    I'm sorry for late answer. I tried to reproduce the bug on gcc 4.8. But with no success. That's why let this ticket be closed. If the bug will reproduce I'll let you know. Thanks for fast response!

  11. nlohmann commented on May 29, 2016

    @nlohmann
    Owner

    Thanks for checking back. I'd love to get rid of all bugs, but you understand I need a way to reproduce it to debug. All the best!

  12. added
    solution: invalid
    and removed
    state: please discuss
    on Jun 19, 2016
  13. Pilipets commented on Jun 29, 2021

    @Pilipets

    That's interesting, but I'm using MSVC v140 C++14, and the whole program freezes on this line AllocatorTraits::construct(alloc, object.get(), std::forward<Args>(args)...);

    Inspecting the calling stack, I found out that it came from std::pair<iterator, bool> emplace(Args&& ... args)

            // transform null object into an object
            if (is_null())
            {
                m_type = value_t::object;
                m_value = value_t::object;
                assert_invariant();
            }
    

    I can't provide the minimum repro example at this point as it freezes when calling from another thread and .dll...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugsolution: invalid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions