diff options
author | Joshua Colp <jcolp@digium.com> | 2015-12-14 14:04:15 -0400 |
---|---|---|
committer | Joshua Colp <jcolp@digium.com> | 2015-12-16 17:17:30 -0400 |
commit | a9d6fc571d08de45ac3b9cfb78db9007f7b8ed48 (patch) | |
tree | 349549e7e53d01e15d9eaeaeec9324e2fbef740e /res | |
parent | 280adca0a55f5fa75dc562ded5a2daf9df6a6184 (diff) |
json: Audit ast_json_* usage for thread safety.
The JSON library Asterisk uses, jansson, is not thread
safe for us in a few ways. To help with this wrappers for JSON
object reference count increasing and decreasing were added
which use a global lock to ensure they don't clobber over
each other. This does not extend to reference count manipulation
within the jansson library itself. This means you can't safely
use the object borrowing specifier (O) in ast_json_pack and
you can't share JSON instances between objects.
This change removes uses of the O specifier and replaces them
with the o specifier and an explicit ast_json_ref. Some cases
of instance sharing have also been removed.
ASTERISK-25601 #close
Change-Id: I06550d8b0cc1bfeb56cab580a4e608ae4f1ec7d1
Diffstat (limited to 'res')
-rw-r--r-- | res/res_fax.c | 4 | ||||
-rw-r--r-- | res/res_stasis.c | 6 | ||||
-rw-r--r-- | res/res_stasis_playback.c | 4 | ||||
-rw-r--r-- | res/res_stasis_recording.c | 4 | ||||
-rw-r--r-- | res/stasis/app.c | 4 |
5 files changed, 11 insertions, 11 deletions
diff --git a/res/res_fax.c b/res/res_fax.c index e947c91c1..ef0e27696 100644 --- a/res/res_fax.c +++ b/res/res_fax.c @@ -2028,14 +2028,14 @@ static int report_receive_fax_status(struct ast_channel *chan, const char *filen fax_bitrate = ast_strdupa(fax_bitrate); } - json_object = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: O}", + json_object = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: o}", "type", "receive", "remote_station_id", S_OR(remote_station_id, ""), "local_station_id", S_OR(local_station_id, ""), "fax_pages", S_OR(fax_pages, ""), "fax_resolution", S_OR(fax_resolution, ""), "fax_bitrate", S_OR(fax_bitrate, ""), - "filenames", json_array); + "filenames", ast_json_ref(json_array)); if (!json_object) { return -1; } diff --git a/res/res_stasis.c b/res/res_stasis.c index 1cab8c389..94b037e69 100644 --- a/res/res_stasis.c +++ b/res/res_stasis.c @@ -150,10 +150,10 @@ static struct ast_json *stasis_start_to_json(struct stasis_message *message, return NULL; } - msg = ast_json_pack("{s: s, s: O, s: O, s: o}", + msg = ast_json_pack("{s: s, s: o, s: o, s: o}", "type", "StasisStart", - "timestamp", ast_json_object_get(payload->blob, "timestamp"), - "args", ast_json_object_get(payload->blob, "args"), + "timestamp", ast_json_copy(ast_json_object_get(payload->blob, "timestamp")), + "args", ast_json_deep_copy(ast_json_object_get(payload->blob, "args")), "channel", ast_channel_snapshot_to_json(payload->channel, NULL)); if (!msg) { ast_log(LOG_ERROR, "Failed to pack JSON for StasisStart message\n"); diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c index dc6e8f2b8..779dd7755 100644 --- a/res/res_stasis_playback.c +++ b/res/res_stasis_playback.c @@ -105,9 +105,9 @@ static struct ast_json *playback_to_json(struct stasis_message *message, return NULL; } - return ast_json_pack("{s: s, s: O}", + return ast_json_pack("{s: s, s: o}", "type", type, - "playback", blob); + "playback", ast_json_deep_copy(blob)); } STASIS_MESSAGE_TYPE_DEFN(stasis_app_playback_snapshot_type, diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c index 50e0697b1..392d92c8e 100644 --- a/res/res_stasis_recording.c +++ b/res/res_stasis_recording.c @@ -91,9 +91,9 @@ static struct ast_json *recording_to_json(struct stasis_message *message, return NULL; } - return ast_json_pack("{s: s, s: O}", + return ast_json_pack("{s: s, s: o}", "type", type, - "recording", blob); + "recording", ast_json_deep_copy(blob)); } STASIS_MESSAGE_TYPE_DEFN(stasis_app_recording_snapshot_type, diff --git a/res/stasis/app.c b/res/stasis/app.c index 353918241..4e18aa5ae 100644 --- a/res/stasis/app.c +++ b/res/stasis/app.c @@ -610,11 +610,11 @@ static int message_received_handler(const char *endpoint_id, struct ast_json *js return -1; } - app_send(app, ast_json_pack("{s: s, s: o, s: o, s: O}", + app_send(app, ast_json_pack("{s: s, s: o, s: o, s: o}", "type", "TextMessageReceived", "timestamp", ast_json_timeval(ast_tvnow(), NULL), "endpoint", json_endpoint, - "message", json_msg)); + "message", ast_json_ref(json_msg))); return 0; } |