{"action":"created","issue":{"url":"https://api.github.com/repos/xiehuc/pidgin-lwqq/issues/631","labels_url":"https://api.github.com/repos/xiehuc/pidgin-lwqq/issues/631/labels{/name}","comments_url":"https://api.github.com/repos/xiehuc/pidgin-lwqq/issues/631/comments","events_url":"https://api.github.com/repos/xiehuc/pidgin-lwqq/issues/631/events","html_url":"https://github.com/xiehuc/pidgin-lwqq/issues/631","id":66747392,"number":631,"title":"竟态条件","user":{"login":"sunshiney","id":7091130,"avatar_url":"https://avatars.githubusercontent.com/u/7091130?v=3","gravatar_id":"","url":"https://api.github.com/users/sunshiney","html_url":"https://github.com/sunshiney","followers_url":"https://api.github.com/users/sunshiney/followers","following_url":"https://api.github.com/users/sunshiney/following{/other_user}","gists_url":"https://api.github.com/users/sunshiney/gists{/gist_id}","starred_url":"https://api.github.com/users/sunshiney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sunshiney/subscriptions","organizations_url":"https://api.github.com/users/sunshiney/orgs","repos_url":"https://api.github.com/users/sunshiney/repos","events_url":"https://api.github.com/users/sunshiney/events{/privacy}","received_events_url":"https://api.github.com/users/sunshiney/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-07T01:41:51Z","updated_at":"2015-04-07T02:17:08Z","closed_at":null,"body":"您好，我最近在用kopete qq频繁崩溃，查看了代码，看到一处竟态条件没有保护，可能会导致内存异常，因为也只是在工作之余看了一周的时间，不知道我的问题是否确实是个问题，还请帮忙分析一下。\r\n问题描述如下：\r\n线程1执行：\r\nLwqqAsyncEvset* set = lwqq_async_evset_new();\r\nev = lwqq_info_get_single_long_nick(lc, buddy);\r\nlwqq_async_evset_add_event(set, ev);\r\nev = lwqq_info_get_level(lc, buddy);\r\nlwqq_async_evset_add_event(set, ev);\r\n\r\n线程2执行：\r\ncheck_multi_info里面的\r\n\t\t\t//执行完成时候的回调\r\n\t\t\tif(lwqq_client_valid(lc))\r\n\t\t\t\tlwqq_client_dispatch(lc,_C_(p,async_complete,conn));\r\n时候，会把set释放掉。\r\n\r\n这个时候线程1和线程2存在竟态条件，如果线程1执行完第一个add_event，线程2把set释放了，线程1再执行第二个add_event，这样它将引用了一个释放掉的内存空间，这样就会导致程序崩溃。\r\n\r\n请看看是否会出现这个的问题呢？如果有应该如何使用该库才能避免此类问题出现呢？"},"comment":{"url":"https://api.github.com/repos/xiehuc/pidgin-lwqq/issues/comments/90317282","html_url":"https://github.com/xiehuc/pidgin-lwqq/issues/631#issuecomment-90317282","issue_url":"https://api.github.com/repos/xiehuc/pidgin-lwqq/issues/631","id":90317282,"user":{"login":"xiehuc","id":571878,"avatar_url":"https://avatars.githubusercontent.com/u/571878?v=3","gravatar_id":"","url":"https://api.github.com/users/xiehuc","html_url":"https://github.com/xiehuc","followers_url":"https://api.github.com/users/xiehuc/followers","following_url":"https://api.github.com/users/xiehuc/following{/other_user}","gists_url":"https://api.github.com/users/xiehuc/gists{/gist_id}","starred_url":"https://api.github.com/users/xiehuc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiehuc/subscriptions","organizations_url":"https://api.github.com/users/xiehuc/orgs","repos_url":"https://api.github.com/users/xiehuc/repos","events_url":"https://api.github.com/users/xiehuc/events{/privacy}","received_events_url":"https://api.github.com/users/xiehuc/received_events","type":"User","site_admin":false},"created_at":"2015-04-07T02:17:08Z","updated_at":"2015-04-07T02:17:08Z","body":"因为网络通信的时间肯定要比本地执行代码的时间慢很多，因此不会说执行完第一个add event就马上complete把set释放了。kopete qq可能是用的早期lwqq库没有更新。崩溃的话最好还是运行gdb在哪出问题的能很快定位到。\r\n\r\nEl Psy Congroo\r\n\r\n在 2015年4月7日，09:41，sunshiney <notifications@github.com> 写道：\r\n\r\n> 您好，我最近在用kopete qq频繁崩溃，查看了代码，看到一处竟态条件没有保护，可能会导致内存异常，因为也只是在工作之余看了一周的时间，不知道我的问题是否确实是个问题，还请帮忙分析一下。\r\n> 问题描述如下：\r\n> 线程1执行：\r\n> LwqqAsyncEvset* set = lwqq_async_evset_new();\r\n> ev = lwqq_info_get_single_long_nick(lc, buddy);\r\n> lwqq_async_evset_add_event(set, ev);\r\n> ev = lwqq_info_get_level(lc, buddy);\r\n> lwqq_async_evset_add_event(set, ev);\r\n> \r\n> 线程2执行：\r\n> check_multi_info里面的\r\n> //执行完成时候的回调\r\n> if(lwqq_client_valid(lc))\r\n> lwqq_client_dispatch(lc,C(p,async_complete,conn));\r\n> 时候，会把set释放掉。\r\n> \r\n> 这个时候线程1和线程2存在竟态条件，如果线程1执行完第一个add_event，线程2把set释放了，线程1再执行第二个add_event，这样它将引用了一个释放掉的内存空间，这样就会导致程序崩溃。\r\n> \r\n> 请看看是否会出现这个的问题呢？如果有应该如何使用该库才能避免此类问题出现呢？\r\n> \r\n> —\r\n> Reply to this email directly or view it on GitHub.\r\n> \r\n"}}