[stx-metal] No need to json_object_put for those json_obj created by json_object_object_get_ex.

Bug #1807097 reported by Yan Chen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
StarlingX
Fix Released
Medium
Yan Chen

Bug Description

Title
-----
[stx-metal] No need to json_object_put for those json_obj created by json_object_object_get_ex.

Brief Description
-----------------
Source Code: mtce-common/src/common/jsonUtil.cpp
There is no need to manually adjust reference counts through the json_object_put(), for those json_obj created by json_object_object_get_ex().
This is stated in the json_object.h of json-c, both 0.11 and the latest version.
But on 0.11, json_object_put() will not assert for the ref_count issue, while on the latest version it will.
It is not an urgent issue, but we'd better fix it to follow the json-c spec.

Severity
--------
Critical

Steps to Reproduce
------------------
Run mtcAgent with new version json-c library (test version 0.13.1).

Expected Behavior
------------------
mtcAgent should work properly.

Actual Behavior
----------------
Crashed with assersion:
mtcAgent: json_object.c:189: json_object_put: Assertion `jso->_ref_count > 0' failed.

Reproducibility
---------------
Run mtcAgent with json-c version 0.13.1.

System Configuration
--------------------
json-c version 0.13.1

Branch/Pull Time/Commit
-----------------------
master

Timestamp/Logs
--------------
2018-12-06T16:24:48.468 [25084.00057] localhost mtcAgent mtc mtcNodeCtrl.cpp ( 963) _self_provision : Info : My Hostname : controller-0
2018-12-06T16:24:48.544 [25084.00058] controller-0 mtcAgent com nodeUtil.cpp ( 439) get_ip_addresses : Info : Local IP : 2001:db8::2
2018-12-06T16:24:48.618 [25084.00059] controller-0 mtcAgent com nodeUtil.cpp ( 452) get_ip_addresses : Info : Floating IP : 192.168.204.2
2018-12-06T16:24:48.618 [25084.00060] controller-0 mtcAgent com nodeUtil.cpp ( 643) get_iface_macaddr : Info : Mac Address : 00:00:00:00:00:00
2018-12-06T16:24:48.618 [25084.00061] controller-0 mtcAgent --- nodeBase.cpp ( 681) log_adminAction : Info : controller-0 Add Action
2018-12-06T16:24:48.618 [25084.00062] controller-0 mtcAgent tok tokenUtil.cpp ( 707) tokenUtil_new_token : Info : controller-0 Requesting Authentication Token
2018-12-06T16:24:48.618 [25084.00063] controller-0 mtcAgent tok tokenUtil.cpp ( 118) tokenUtil_get_first : Info : controller-0 waiting on token request completion loop:0
mtcAgent: json_object.c:189: json_object_put: Assertion `jso->_ref_count > 0' failed.
./rebuild.sh: line 10: 25083 Aborted sudo ./maintenance/mtcAgent -fa

Yan Chen (ychen2u)
Changed in starlingx:
assignee: nobody → Yan Chen (ychen2u)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to stx-metal (master)

Fix proposed to branch: master
Review: https://review.openstack.org/623149

Changed in starlingx:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to stx-metal (master)

Reviewed: https://review.openstack.org/623149
Committed: https://git.openstack.org/cgit/openstack/stx-metal/commit/?id=a92c543fd574e027f0de0bd17d8a67090364ef3d
Submitter: Zuul
Branch: master

commit a92c543fd574e027f0de0bd17d8a67090364ef3d
Author: Yan Chen <email address hidden>
Date: Fri Dec 7 00:47:21 2018 +0800

    No json_object_put() for the json_obj created by json_object_object_get_ex().

    It is stated in the json_object.h from version 0.11:
    https://github.com/json-c/json-c/blob/json-c-0.11/json_object.h#L271

    As on json-c 0.11, there's no assert to check for the ref_count, we wont get
      crashed. But on json-c 0.13.1 (latest release), json_object_put will check
      for the ref_count first, so mtcAgent will crash.

    Test Done:
    Run mtcAgent with json-c version 0.13.1 with this patch, no crash found.

    Closes-Bug: 1807097

    Change-Id: I7f954c97804ae01f831c94a36b9dbdbb34dbf083
    Signed-off-by: Yan Chen <email address hidden>

Changed in starlingx:
status: In Progress → Fix Released
Revision history for this message
Eric MacDonald (rocksolidmtce) wrote :

The update this bug report was closed against has been reverted due to a compile error due to the declaration of an unused variable.

Please fix and retest.

Revision history for this message
Ghada Khalil (gkhalil) wrote :

Re-opening the launchpad as the original commit was reverted by:
https://review.openstack.org/#/c/623311/

A new fix will need to be submitted

tags: added: stx.metal
Changed in starlingx:
status: Fix Released → In Progress
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to stx-metal (master)

Fix proposed to branch: master
Review: https://review.openstack.org/623367

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to stx-metal (master)

Reviewed: https://review.openstack.org/623367
Committed: https://git.openstack.org/cgit/openstack/stx-metal/commit/?id=1c38aff32a08cdd65080b8baa6d4fe02ee2083a4
Submitter: Zuul
Branch: master

commit 1c38aff32a08cdd65080b8baa6d4fe02ee2083a4
Author: Yan Chen <email address hidden>
Date: Fri Dec 7 19:20:16 2018 +0800

    No json_object_put() for the json_obj created by json_object_object_get_ex().

    It is stated in the json_object.h from version 0.11:
    https://github.com/json-c/json-c/blob/json-c-0.11/json_object.h#L271

    As on json-c 0.11, there's no assert to check for the ref_count, we wont get
      crashed. But on json-c 0.13.1 (latest release), json_object_put will check
      for the ref_count first, so mtcAgent will crash.

    Test Done:
    Run mtcAgent with json-c version 0.13.1 with this patch, no crash found.

    Closes-Bug: 1807097

    Change-Id: I35e5c1cad2e16ee0b6fc639380f1bdd3b64a7018
    Signed-off-by: Yan Chen <email address hidden>

Changed in starlingx:
status: In Progress → Fix Released
Ghada Khalil (gkhalil)
tags: added: stx.2019.03
Ken Young (kenyis)
tags: added: stx.2019.05
removed: stx.2019.03
Ken Young (kenyis)
tags: added: stx.2.0
removed: stx.2019.05
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.