{"action":"created","comment":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments/26937244","id":26937244,"diff_hunk":"@@ -87,16 +103,21 @@ void ng_pktbuf_release(ng_pktsnip_t *pkt)\n         return;\n     }\n \n-    atomic_set_return(&(pkt->users), pkt->users - 1);\n+    mutex_lock(&_pktbuf_mutex);\n \n-    if (pkt->users == 0 && _pktbuf_internal_contains(pkt->data)) {\n-        mutex_lock(&_pktbuf_mutex);\n+    while (pkt != NULL) {\n+        pkt->users--;\n \n-        _pktbuf_internal_free(pkt->data);\n-        _pktbuf_internal_free(pkt);\n+        if (pkt->users == 0 && _pktbuf_internal_contains(pkt->data)) {","path":"sys/net/crosslayer/ng_pktbuf/ng_pktbuf.c","position":53,"original_position":53,"commit_id":"788c3bd252513aea0d5aef25d04d82401807e7c1","original_commit_id":"754a4527a49a622617ee48579f916d7e2a55099a","user":{"login":"haukepetersen","id":620834,"avatar_url":"https://avatars.githubusercontent.com/u/620834?v=3","gravatar_id":"","url":"https://api.github.com/users/haukepetersen","html_url":"https://github.com/haukepetersen","followers_url":"https://api.github.com/users/haukepetersen/followers","following_url":"https://api.github.com/users/haukepetersen/following{/other_user}","gists_url":"https://api.github.com/users/haukepetersen/gists{/gist_id}","starred_url":"https://api.github.com/users/haukepetersen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haukepetersen/subscriptions","organizations_url":"https://api.github.com/users/haukepetersen/orgs","repos_url":"https://api.github.com/users/haukepetersen/repos","events_url":"https://api.github.com/users/haukepetersen/events{/privacy}","received_events_url":"https://api.github.com/users/haukepetersen/received_events","type":"User","site_admin":false},"body":"don't we need to call `_pktbuf_internal_free(pkt)` always if `pkt->users == 0`, independent of `pkt->data`? So this if condition needs to be split up in my opinion:\r\n```c\r\nif (pkt->users == 0) {\r\n    _pktbuf_internal_free(pkt);\r\n    if (_pktbuf_internal_contains(pkt->data)) {\r\n        _pktbuf_internal_free(pkt);\r\n    }\r\n}\r\n```","created_at":"2015-03-23T13:51:20Z","updated_at":"2015-03-23T13:51:20Z","html_url":"https://github.com/RIOT-OS/RIOT/pull/2563#discussion_r26937244","pull_request_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/2563","_links":{"self":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments/26937244"},"html":{"href":"https://github.com/RIOT-OS/RIOT/pull/2563#discussion_r26937244"},"pull_request":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/2563"}}},"pull_request":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/2563","id":30761392,"html_url":"https://github.com/RIOT-OS/RIOT/pull/2563","diff_url":"https://github.com/RIOT-OS/RIOT/pull/2563.diff","patch_url":"https://github.com/RIOT-OS/RIOT/pull/2563.patch","issue_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/2563","number":2563,"state":"open","locked":false,"title":"ng_pktbuf: change semantics for received packets","user":{"login":"authmillenon","id":675644,"avatar_url":"https://avatars.githubusercontent.com/u/675644?v=3","gravatar_id":"","url":"https://api.github.com/users/authmillenon","html_url":"https://github.com/authmillenon","followers_url":"https://api.github.com/users/authmillenon/followers","following_url":"https://api.github.com/users/authmillenon/following{/other_user}","gists_url":"https://api.github.com/users/authmillenon/gists{/gist_id}","starred_url":"https://api.github.com/users/authmillenon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/authmillenon/subscriptions","organizations_url":"https://api.github.com/users/authmillenon/orgs","repos_url":"https://api.github.com/users/authmillenon/repos","events_url":"https://api.github.com/users/authmillenon/events{/privacy}","received_events_url":"https://api.github.com/users/authmillenon/received_events","type":"User","site_admin":false},"body":"Sending packets remain in the same order, receiving packets are reversed. This way we save memory on `ng_pktbuf_start_write()`, since only the parts of the packets of interest for later layers in the line are duplicated:\r\n\r\nSome extreme examples below (`next` pointer always points up). Normally, with sending this would only apply for `netif` headers in multicast and L3 in some corner cases. For receiving this can only happen if there are sniffers or dual stacks involved.\r\n\r\n```\r\nSending                          Receiving\r\n=======                          =========\r\n\r\n* Payload                        * netif header\r\n|\\                               |\\\r\n| * L4 header 1                  | * L2.5 header 1\r\n| * L3 header 1                  | * L3 header 1 \r\n| * netif header 1               | * L4 header 1\r\n*   L4 header 2                  | * Payload 1\r\n|\\                               *   L3 header 2\r\n| * Network header 2             |\\\r\n| * netif header 2               | * L4 header 2\r\n*   Network header 3             | * Payload 2\r\n|\\                               *   Payload 3\r\n| * netif header 3\r\n*   netif header 4\r\n```","created_at":"2015-03-09T13:50:00Z","updated_at":"2015-03-23T13:51:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"688df4d7a17c69384f18a0e26d986838d899f6ca","assignee":{"login":"haukepetersen","id":620834,"avatar_url":"https://avatars.githubusercontent.com/u/620834?v=3","gravatar_id":"","url":"https://api.github.com/users/haukepetersen","html_url":"https://github.com/haukepetersen","followers_url":"https://api.github.com/users/haukepetersen/followers","following_url":"https://api.github.com/users/haukepetersen/following{/other_user}","gists_url":"https://api.github.com/users/haukepetersen/gists{/gist_id}","starred_url":"https://api.github.com/users/haukepetersen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haukepetersen/subscriptions","organizations_url":"https://api.github.com/users/haukepetersen/orgs","repos_url":"https://api.github.com/users/haukepetersen/repos","events_url":"https://api.github.com/users/haukepetersen/events{/privacy}","received_events_url":"https://api.github.com/users/haukepetersen/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/RIOT-OS/RIOT/milestones/11","html_url":"https://github.com/RIOT-OS/RIOT/milestones/Network%20Stack%20Task%20Force","labels_url":"https://api.github.com/repos/RIOT-OS/RIOT/milestones/11/labels","id":968921,"number":11,"title":"Network Stack Task Force","description":"The goal of this milestone is to implement the redesign of the network stack.\r\n\r\nTodo list at #2278.","creator":{"login":"OlegHahm","id":1590423,"avatar_url":"https://avatars.githubusercontent.com/u/1590423?v=3","gravatar_id":"","url":"https://api.github.com/users/OlegHahm","html_url":"https://github.com/OlegHahm","followers_url":"https://api.github.com/users/OlegHahm/followers","following_url":"https://api.github.com/users/OlegHahm/following{/other_user}","gists_url":"https://api.github.com/users/OlegHahm/gists{/gist_id}","starred_url":"https://api.github.com/users/OlegHahm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OlegHahm/subscriptions","organizations_url":"https://api.github.com/users/OlegHahm/orgs","repos_url":"https://api.github.com/users/OlegHahm/repos","events_url":"https://api.github.com/users/OlegHahm/events{/privacy}","received_events_url":"https://api.github.com/users/OlegHahm/received_events","type":"User","site_admin":false},"open_issues":16,"closed_issues":37,"state":"open","created_at":"2015-02-06T16:04:53Z","updated_at":"2015-03-20T18:30:17Z","due_on":"2015-04-07T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/2563/commits","review_comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/2563/comments","review_comment_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/2563/comments","statuses_url":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/788c3bd252513aea0d5aef25d04d82401807e7c1","head":{"label":"authmillenon:ng_pktbuf/fix/semantics","ref":"ng_pktbuf/fix/semantics","sha":"788c3bd252513aea0d5aef25d04d82401807e7c1","user":{"login":"authmillenon","id":675644,"avatar_url":"https://avatars.githubusercontent.com/u/675644?v=3","gravatar_id":"","url":"https://api.github.com/users/authmillenon","html_url":"https://github.com/authmillenon","followers_url":"https://api.github.com/users/authmillenon/followers","following_url":"https://api.github.com/users/authmillenon/following{/other_user}","gists_url":"https://api.github.com/users/authmillenon/gists{/gist_id}","starred_url":"https://api.github.com/users/authmillenon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/authmillenon/subscriptions","organizations_url":"https://api.github.com/users/authmillenon/orgs","repos_url":"https://api.github.com/users/authmillenon/repos","events_url":"https://api.github.com/users/authmillenon/events{/privacy}","received_events_url":"https://api.github.com/users/authmillenon/received_events","type":"User","site_admin":false},"repo":{"id":7667624,"name":"RIOT","full_name":"authmillenon/RIOT","owner":{"login":"authmillenon","id":675644,"avatar_url":"https://avatars.githubusercontent.com/u/675644?v=3","gravatar_id":"","url":"https://api.github.com/users/authmillenon","html_url":"https://github.com/authmillenon","followers_url":"https://api.github.com/users/authmillenon/followers","following_url":"https://api.github.com/users/authmillenon/following{/other_user}","gists_url":"https://api.github.com/users/authmillenon/gists{/gist_id}","starred_url":"https://api.github.com/users/authmillenon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/authmillenon/subscriptions","organizations_url":"https://api.github.com/users/authmillenon/orgs","repos_url":"https://api.github.com/users/authmillenon/repos","events_url":"https://api.github.com/users/authmillenon/events{/privacy}","received_events_url":"https://api.github.com/users/authmillenon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/authmillenon/RIOT","description":"RIOT OS -  The revolutionary IoT OS","fork":true,"url":"https://api.github.com/repos/authmillenon/RIOT","forks_url":"https://api.github.com/repos/authmillenon/RIOT/forks","keys_url":"https://api.github.com/repos/authmillenon/RIOT/keys{/key_id}","collaborators_url":"https://api.github.com/repos/authmillenon/RIOT/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/authmillenon/RIOT/teams","hooks_url":"https://api.github.com/repos/authmillenon/RIOT/hooks","issue_events_url":"https://api.github.com/repos/authmillenon/RIOT/issues/events{/number}","events_url":"https://api.github.com/repos/authmillenon/RIOT/events","assignees_url":"https://api.github.com/repos/authmillenon/RIOT/assignees{/user}","branches_url":"https://api.github.com/repos/authmillenon/RIOT/branches{/branch}","tags_url":"https://api.github.com/repos/authmillenon/RIOT/tags","blobs_url":"https://api.github.com/repos/authmillenon/RIOT/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/authmillenon/RIOT/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/authmillenon/RIOT/git/refs{/sha}","trees_url":"https://api.github.com/repos/authmillenon/RIOT/git/trees{/sha}","statuses_url":"https://api.github.com/repos/authmillenon/RIOT/statuses/{sha}","languages_url":"https://api.github.com/repos/authmillenon/RIOT/languages","stargazers_url":"https://api.github.com/repos/authmillenon/RIOT/stargazers","contributors_url":"https://api.github.com/repos/authmillenon/RIOT/contributors","subscribers_url":"https://api.github.com/repos/authmillenon/RIOT/subscribers","subscription_url":"https://api.github.com/repos/authmillenon/RIOT/subscription","commits_url":"https://api.github.com/repos/authmillenon/RIOT/commits{/sha}","git_commits_url":"https://api.github.com/repos/authmillenon/RIOT/git/commits{/sha}","comments_url":"https://api.github.com/repos/authmillenon/RIOT/comments{/number}","issue_comment_url":"https://api.github.com/repos/authmillenon/RIOT/issues/comments{/number}","contents_url":"https://api.github.com/repos/authmillenon/RIOT/contents/{+path}","compare_url":"https://api.github.com/repos/authmillenon/RIOT/compare/{base}...{head}","merges_url":"https://api.github.com/repos/authmillenon/RIOT/merges","archive_url":"https://api.github.com/repos/authmillenon/RIOT/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/authmillenon/RIOT/downloads","issues_url":"https://api.github.com/repos/authmillenon/RIOT/issues{/number}","pulls_url":"https://api.github.com/repos/authmillenon/RIOT/pulls{/number}","milestones_url":"https://api.github.com/repos/authmillenon/RIOT/milestones{/number}","notifications_url":"https://api.github.com/repos/authmillenon/RIOT/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/authmillenon/RIOT/labels{/name}","releases_url":"https://api.github.com/repos/authmillenon/RIOT/releases{/id}","created_at":"2013-01-17T14:31:57Z","updated_at":"2015-03-21T18:26:28Z","pushed_at":"2015-03-23T13:50:50Z","git_url":"git://github.com/authmillenon/RIOT.git","ssh_url":"git@github.com:authmillenon/RIOT.git","clone_url":"https://github.com/authmillenon/RIOT.git","svn_url":"https://github.com/authmillenon/RIOT","homepage":null,"size":32204,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"RIOT-OS:master","ref":"master","sha":"b9f4cdc3ae52bfd626a7ea9f368c5138a998005b","user":{"login":"RIOT-OS","id":3079480,"avatar_url":"https://avatars.githubusercontent.com/u/3079480?v=3","gravatar_id":"","url":"https://api.github.com/users/RIOT-OS","html_url":"https://github.com/RIOT-OS","followers_url":"https://api.github.com/users/RIOT-OS/followers","following_url":"https://api.github.com/users/RIOT-OS/following{/other_user}","gists_url":"https://api.github.com/users/RIOT-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/RIOT-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RIOT-OS/subscriptions","organizations_url":"https://api.github.com/users/RIOT-OS/orgs","repos_url":"https://api.github.com/users/RIOT-OS/repos","events_url":"https://api.github.com/users/RIOT-OS/events{/privacy}","received_events_url":"https://api.github.com/users/RIOT-OS/received_events","type":"Organization","site_admin":false},"repo":{"id":7370241,"name":"RIOT","full_name":"RIOT-OS/RIOT","owner":{"login":"RIOT-OS","id":3079480,"avatar_url":"https://avatars.githubusercontent.com/u/3079480?v=3","gravatar_id":"","url":"https://api.github.com/users/RIOT-OS","html_url":"https://github.com/RIOT-OS","followers_url":"https://api.github.com/users/RIOT-OS/followers","following_url":"https://api.github.com/users/RIOT-OS/following{/other_user}","gists_url":"https://api.github.com/users/RIOT-OS/gists{/gist_id}","starred_url":"https://api.github.com/users/RIOT-OS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RIOT-OS/subscriptions","organizations_url":"https://api.github.com/users/RIOT-OS/orgs","repos_url":"https://api.github.com/users/RIOT-OS/repos","events_url":"https://api.github.com/users/RIOT-OS/events{/privacy}","received_events_url":"https://api.github.com/users/RIOT-OS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RIOT-OS/RIOT","description":"RIOT -  The friendly OS for IoT","fork":false,"url":"https://api.github.com/repos/RIOT-OS/RIOT","forks_url":"https://api.github.com/repos/RIOT-OS/RIOT/forks","keys_url":"https://api.github.com/repos/RIOT-OS/RIOT/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RIOT-OS/RIOT/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RIOT-OS/RIOT/teams","hooks_url":"https://api.github.com/repos/RIOT-OS/RIOT/hooks","issue_events_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/events{/number}","events_url":"https://api.github.com/repos/RIOT-OS/RIOT/events","assignees_url":"https://api.github.com/repos/RIOT-OS/RIOT/assignees{/user}","branches_url":"https://api.github.com/repos/RIOT-OS/RIOT/branches{/branch}","tags_url":"https://api.github.com/repos/RIOT-OS/RIOT/tags","blobs_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/refs{/sha}","trees_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/{sha}","languages_url":"https://api.github.com/repos/RIOT-OS/RIOT/languages","stargazers_url":"https://api.github.com/repos/RIOT-OS/RIOT/stargazers","contributors_url":"https://api.github.com/repos/RIOT-OS/RIOT/contributors","subscribers_url":"https://api.github.com/repos/RIOT-OS/RIOT/subscribers","subscription_url":"https://api.github.com/repos/RIOT-OS/RIOT/subscription","commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/commits{/sha}","git_commits_url":"https://api.github.com/repos/RIOT-OS/RIOT/git/commits{/sha}","comments_url":"https://api.github.com/repos/RIOT-OS/RIOT/comments{/number}","issue_comment_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues/comments{/number}","contents_url":"https://api.github.com/repos/RIOT-OS/RIOT/contents/{+path}","compare_url":"https://api.github.com/repos/RIOT-OS/RIOT/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RIOT-OS/RIOT/merges","archive_url":"https://api.github.com/repos/RIOT-OS/RIOT/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RIOT-OS/RIOT/downloads","issues_url":"https://api.github.com/repos/RIOT-OS/RIOT/issues{/number}","pulls_url":"https://api.github.com/repos/RIOT-OS/RIOT/pulls{/number}","milestones_url":"https://api.github.com/repos/RIOT-OS/RIOT/milestones{/number}","notifications_url":"https://api.github.com/repos/RIOT-OS/RIOT/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RIOT-OS/RIOT/labels{/name}","releases_url":"https://api.github.com/repos/RIOT-OS/RIOT/releases{/id}","created_at":"2012-12-29T20:38:40Z","updated_at":"2015-03-23T08:37:44Z","pushed_at":"2015-03-23T13:50:50Z","git_url":"git://github.com/RIOT-OS/RIOT.git","ssh_url":"git@github.com:RIOT-OS/RIOT.git","clone_url":"https://github.com/RIOT-OS/RIOT.git","svn_url":"https://github.com/RIOT-OS/RIOT","homepage":"https://github.com/RIOT-OS/RIOT/wiki","size":89398,"stargazers_count":298,"watchers_count":298,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":245,"mirror_url":null,"open_issues_count":307,"forks":245,"open_issues":307,"watchers":298,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/2563"},"html":{"href":"https://github.com/RIOT-OS/RIOT/pull/2563"},"issue":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/issues/2563"},"comments":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/issues/2563/comments"},"review_comments":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/2563/comments"},"review_comment":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/pulls/2563/commits"},"statuses":{"href":"https://api.github.com/repos/RIOT-OS/RIOT/statuses/788c3bd252513aea0d5aef25d04d82401807e7c1"}}}}