{"action":"created","issue":{"url":"https://api.github.com/repos/SamsungARTIK/artik-sdk/issues/34","repository_url":"https://api.github.com/repos/SamsungARTIK/artik-sdk","labels_url":"https://api.github.com/repos/SamsungARTIK/artik-sdk/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/SamsungARTIK/artik-sdk/issues/34/comments","events_url":"https://api.github.com/repos/SamsungARTIK/artik-sdk/issues/34/events","html_url":"https://github.com/SamsungARTIK/artik-sdk/issues/34","id":380723841,"node_id":"MDU6SXNzdWUzODA3MjM4NDE=","number":34,"title":"Glib crash issue with the run() function in Artik::Loop","user":{"login":"mmajb","id":31699522,"node_id":"MDQ6VXNlcjMxNjk5NTIy","avatar_url":"https://avatars3.githubusercontent.com/u/31699522?v=4","gravatar_id":"","url":"https://api.github.com/users/mmajb","html_url":"https://github.com/mmajb","followers_url":"https://api.github.com/users/mmajb/followers","following_url":"https://api.github.com/users/mmajb/following{/other_user}","gists_url":"https://api.github.com/users/mmajb/gists{/gist_id}","starred_url":"https://api.github.com/users/mmajb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmajb/subscriptions","organizations_url":"https://api.github.com/users/mmajb/orgs","repos_url":"https://api.github.com/users/mmajb/repos","events_url":"https://api.github.com/users/mmajb/events{/privacy}","received_events_url":"https://api.github.com/users/mmajb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-11-14T14:29:32Z","updated_at":"2018-11-22T08:47:58Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\nI'm using an Artik 530s with Ubuntu and Artik SDK version 1.8-3. I'm facing an issue right now. The application that I've written uses individual MQTT connections with devices created on Artik cloud. Also messages are sent to the devices as well from time to time. All the methods I'm using are asynchronous. Therefore, I also use an instance of the Artik::Loop class and use the run() function in the main function of my application to get callbacks of all the asynchronous calls. The application mostly works fine but occasionally the application crashes with the following error:\r\n\r\n```\r\n(process:11883): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed\r\n**\r\nGLib:ERROR:/build/glib2.0-yKrPuV/glib2.0-2.48.2/./glib/ghash.c:373:g_hash_table_lookup_node: assertion failed: (hash_table->ref_count > 0)\r\nAborted (core dumped)\r\n```\r\n\r\n\r\nI've debugged the dumped core with gdb and the process id 11883 corresponds to my main thread which is blocked on the run() method. Following is the backtrace from gdb:\r\n\r\n```\r\n[Switching to thread 6 (Thread 0xb5f7f270 (LWP 11883))]\r\n#0  syscall () at ../sysdeps/unix/sysv/linux/arm/syscall.S:37\r\n37\t../sysdeps/unix/sysv/linux/arm/syscall.S: No such file or directory.\r\n(gdb) bt\r\n#0  syscall () at ../sysdeps/unix/sysv/linux/arm/syscall.S:37\r\n#1  0xb6917cb8 in g_cond_wait () from /lib/arm-linux-gnueabihf/libglib-2.0.so.0\r\n#2  0xb68e7aa0 in g_main_context_wait () from /lib/arm-linux-gnueabihf/libglib-2.0.so.0\r\n#3  0xb68e859a in g_main_loop_run () from /lib/arm-linux-gnueabihf/libglib-2.0.so.0\r\n#4  0x000192ee in main (argc=1, argv=0xbe8776c4) at Joule_Gateway.cpp:793\r\n```\r\n\r\nLine 793 in Joule_Gateway.cpp corresponds to the run() method. Any ideas on why this might be happening? Thanks.\r\n\r\nRegards,\r\nAhsan"},"comment":{"url":"https://api.github.com/repos/SamsungARTIK/artik-sdk/issues/comments/440955534","html_url":"https://github.com/SamsungARTIK/artik-sdk/issues/34#issuecomment-440955534","issue_url":"https://api.github.com/repos/SamsungARTIK/artik-sdk/issues/34","id":440955534,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MDk1NTUzNA==","user":{"login":"glemercier","id":5225543,"node_id":"MDQ6VXNlcjUyMjU1NDM=","avatar_url":"https://avatars3.githubusercontent.com/u/5225543?v=4","gravatar_id":"","url":"https://api.github.com/users/glemercier","html_url":"https://github.com/glemercier","followers_url":"https://api.github.com/users/glemercier/followers","following_url":"https://api.github.com/users/glemercier/following{/other_user}","gists_url":"https://api.github.com/users/glemercier/gists{/gist_id}","starred_url":"https://api.github.com/users/glemercier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glemercier/subscriptions","organizations_url":"https://api.github.com/users/glemercier/orgs","repos_url":"https://api.github.com/users/glemercier/repos","events_url":"https://api.github.com/users/glemercier/events{/privacy}","received_events_url":"https://api.github.com/users/glemercier/received_events","type":"User","site_admin":false},"created_at":"2018-11-22T08:47:58Z","updated_at":"2018-11-22T08:47:58Z","author_association":"COLLABORATOR","body":"Hi Ahsan,\r\n\r\nI see something that may cause issues in your program. In the following function:\r\n\r\n```\r\nartik_error sendDeviceData(deviceParams devParams, const char* data, artik_cloud_callback callback, artik_ssl_config* ssl)\r\n{\r\n\tconst char* token = devParams.deviceToken.c_str();\r\n\tconst char* deviceId = devParams.deviceId.c_str();\r\n\tartik::Cloud cloud = artik::Cloud(token);\r\n\tartik_error  err = S_OK;\r\n\terr = cloud.send_message_async(deviceId, data,\r\n\t\t      callback, NULL, ssl);\r\n...\r\n}\r\n```\r\nThe `cloud` object has a scope limited to the function, which means that when the function returns its constructor will be called and delete all the associated data. However the loop module will try to call functions and use data from the HTTP module that are likely not valid anymore. The result is unexpected, it could work sometimes and explain why it fails some other. Also in case the callback is not actually called (which seems likely in your case) then the SSL data that was allocated in the `copy_ssl_config` function will not be freed, which could also explains the memory leaks you observed.\r\n\r\nTry to extend the scope of your cloud object by making it global or instantiated in the main function before the `loop->run()` call and see if things get better."}}
{"actor":{"display_login":"glemercier"}}