Skip to content

Continues to fix dap_json usage across cellframe-sdk

dmitriy.gerasimov requested to merge feature/18297 into release-6.0

Fixed critical memory leaks in JSON object handling after migrating to JSON-C semantics:

Memory leak fixes by category:

  • Conditional JSON creation in error paths (12 leaks):

    • dap_chain_net_tx.c: Fixed conditional error message objects
    • Added NULL checks and proper cleanup on allocation failures
  • Nested loops with early exits (4 leaks):

    • dap_chain_net.c: Fixed l_jobj_networks and l_jobj_chain cleanup
    • dap_chain_wallet.c: Fixed balance data objects in nested loops
  • Missing NULL checks after allocation (2 leaks):

    • dap_chain_wallet.c: Added checks for l_json_ret, l_jobj_network, l_jobj_net
    • Implemented proper cleanup on allocation failures
  • Inline creation without parent check (5 leaks):

    • dap_chain_wallet.c: Fixed l_addr_obj, status objects creation
    • dap_chain_net_tx.c: Fixed json_obj_out and json_arr_items checks
    • dap_chain_net.c: Fixed l_jobj_chains_array allocation
  • Array creation without NULL check (5 leaks):

    • dap_chain_datum.c: Fixed l_pkeys_array, l_pkeys_remove_array
    • dap_chain_datum.c: Fixed json_arr_items and json_obj_item in loops
    • dap_chain_net.c: Fixed l_json_networks array creation

API changes fixed:

  • Updated http_status_code_t to dap_http_status_code_t
  • Updated HTTP status constants (Http_Status_* to DAP_HTTP_STATUS_*)
  • Fixed s_callback_decree signature (int->bool, void->int return)

All changes follow JSON-C ownership semantics:

  • dap_json_object_add_* transfers ownership to parent
  • dap_json_object_get_ex returns borrowed reference
  • Proper cleanup on all error paths

Files modified:

  • modules/net/dap_chain_net_tx.c (12 leaks fixed)
  • modules/net/dap_chain_net.c (4 leaks fixed)
  • modules/wallet/dap_chain_wallet.c (5 leaks fixed)
  • modules/datum/dap_chain_datum.c (5 leaks fixed)
  • modules/compose/dap_chain_tx_compose.c (API fix)
  • modules/mempool/dap_chain_mempool.c (API fix)
  • modules/net-srv/dap_chain_net_srv_geoip.c (API fix)
  • modules/net/dap_chain_net_balancer.c (API fix)
  • modules/net/dap_chain_net_node_list.c (API fix)
  • modules/service/vpn/dap_chain_net_srv_vpn.c (API fix)
  • modules/service/xchange/dap_chain_net_srv_xchange.c (API fix)

Tested: All 13 tests pass successfully

Merge request reports

Loading