{"action":"created","comment":{"url":"https://api.github.com/repos/systemd/systemd/pulls/comments/40093215","id":40093215,"diff_hunk":"@@ -207,102 +208,99 @@ static int found_override(const char *top, const char *bottom) {\n         return k;\n }\n \n-static int enumerate_dir_d(Hashmap *top, Hashmap *bottom, Hashmap *drops, const char *toppath, const char *drop) {\n+static int enumerate_dir_d(Hashmap *bottom, const char *toppath, const char *drop) {\n         _cleanup_free_ char *unit = NULL;\n-        _cleanup_free_ char *path = NULL;\n         _cleanup_strv_free_ char **list = NULL;\n-        char **file;\n-        char *c;\n+        char **file, *c, *path;\n         int r;\n \n         assert(!endswith(drop, \"/\"));\n \n-        path = strjoin(toppath, \"/\", drop, NULL);\n-        if (!path)\n-                return -ENOMEM;\n+        log_debug(\"Looking at %s\", toppath);\n \n-        log_debug(\"Looking at %s\", path);\n-\n-        unit = strdup(drop);\n-        if (!unit)\n+        path = strdup(toppath);\n+        if (!path)\n                 return -ENOMEM;\n \n-        c = strrchr(unit, '.');\n+        c = strrchr(path, '.');\n         if (!c)\n                 return -EINVAL;\n         *c = 0;\n \n-        r = get_files_in_directory(path, &list);\n+        r = get_files_in_directory(toppath, &list);\n         if (r < 0)\n-                return log_error_errno(r, \"Failed to enumerate %s: %m\", path);\n+                return log_error_errno(r, \"Failed to enumerate %s: %m\", toppath);\n+\n \n         STRV_FOREACH(file, list) {\n-                Hashmap *h;\n                 int k;\n-                char *p;\n-                char *d;\n+                Hashmap *drops;\n+                char **d, *tmp = NULL, *key;\n \n                 if (!endswith(*file, \".conf\"))\n                         continue;\n \n-                p = strjoin(path, \"/\", *file, NULL);\n-                if (!p)\n-                        return -ENOMEM;\n-                d = p + strlen(toppath) + 1;\n-\n-                log_debug(\"Adding at top: %s %s %s\", d, draw_special_char(DRAW_ARROW), p);\n-                k = hashmap_put(top, d, p);\n-                if (k >= 0) {\n-                        p = strdup(p);\n-                        if (!p)\n-                                return -ENOMEM;\n-                        d = p + strlen(toppath) + 1;\n-                } else if (k != -EEXIST) {\n-                        free(p);\n+                k = unit_name_template(basename(path), &tmp);\n+                if (k < 0 && k != -EINVAL) {\n+                        free(path);\n                         return k;\n                 }\n+                key = tmp ? tmp : basename(path);\n \n-                log_debug(\"Adding at bottom: %s %s %s\", d, draw_special_char(DRAW_ARROW), p);\n-                free(hashmap_remove(bottom, d));\n-                k = hashmap_put(bottom, d, p);\n-                if (k < 0) {\n-                        free(p);\n-                        return k;\n-                }\n+                drops = hashmap_get(bottom, key);\n+                if (!drops) {\n+                        _cleanup_free_ char *p;\n \n-                h = hashmap_get(drops, unit);\n-                if (!h) {\n-                        h = hashmap_new(&string_hash_ops);\n-                        if (!h)\n+                        drops = hashmap_new(&string_hash_ops);\n+                        if (!drops) {\n+                                free(tmp);","path":"src/delta/delta.c","position":116,"original_position":116,"commit_id":"30041c46dbbd94cafcf3deafe85260cbb5807273","original_commit_id":"30041c46dbbd94cafcf3deafe85260cbb5807273","user":{"login":"zonque","id":106304,"avatar_url":"https://avatars.githubusercontent.com/u/106304?v=3","gravatar_id":"","url":"https://api.github.com/users/zonque","html_url":"https://github.com/zonque","followers_url":"https://api.github.com/users/zonque/followers","following_url":"https://api.github.com/users/zonque/following{/other_user}","gists_url":"https://api.github.com/users/zonque/gists{/gist_id}","starred_url":"https://api.github.com/users/zonque/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zonque/subscriptions","organizations_url":"https://api.github.com/users/zonque/orgs","repos_url":"https://api.github.com/users/zonque/repos","events_url":"https://api.github.com/users/zonque/events{/privacy}","received_events_url":"https://api.github.com/users/zonque/received_events","type":"User","site_admin":false},"body":"Instead of doing this in every error path, why not use a `_cleanup_free_` annotation?","created_at":"2015-09-22T14:35:00Z","updated_at":"2015-09-22T14:35:00Z","html_url":"https://github.com/systemd/systemd/pull/1244#discussion_r40093215","pull_request_url":"https://api.github.com/repos/systemd/systemd/pulls/1244","_links":{"self":{"href":"https://api.github.com/repos/systemd/systemd/pulls/comments/40093215"},"html":{"href":"https://github.com/systemd/systemd/pull/1244#discussion_r40093215"},"pull_request":{"href":"https://api.github.com/repos/systemd/systemd/pulls/1244"}}},"pull_request":{"url":"https://api.github.com/repos/systemd/systemd/pulls/1244","id":44755300,"html_url":"https://github.com/systemd/systemd/pull/1244","diff_url":"https://github.com/systemd/systemd/pull/1244.diff","patch_url":"https://github.com/systemd/systemd/pull/1244.patch","issue_url":"https://api.github.com/repos/systemd/systemd/issues/1244","number":1244,"state":"open","locked":false,"title":"delta: support instantiated units and dropins","user":{"login":"jsynacek","id":1014564,"avatar_url":"https://avatars.githubusercontent.com/u/1014564?v=3","gravatar_id":"","url":"https://api.github.com/users/jsynacek","html_url":"https://github.com/jsynacek","followers_url":"https://api.github.com/users/jsynacek/followers","following_url":"https://api.github.com/users/jsynacek/following{/other_user}","gists_url":"https://api.github.com/users/jsynacek/gists{/gist_id}","starred_url":"https://api.github.com/users/jsynacek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsynacek/subscriptions","organizations_url":"https://api.github.com/users/jsynacek/orgs","repos_url":"https://api.github.com/users/jsynacek/repos","events_url":"https://api.github.com/users/jsynacek/events{/privacy}","received_events_url":"https://api.github.com/users/jsynacek/received_events","type":"User","site_admin":false},"body":"Consider the following filesystem contents:\r\n\r\n```\r\n  /usr/lib/systemd/system/httpd.service\r\n    env.conf\r\n  /usr/lib/systemd/system/postfix.service\r\n  /usr/lib/systemd/system/getty@.service\r\n  /usr/lib/systemd/system/getty@.service.d/\r\n    ext.conf\r\n  /etc/systemd/system/getty@tty1.service.d/\r\n    test1-a.conf\r\n    test1-b.conf\r\n  /etc/systemd/system/getty@tty2.service\r\n    test2-c.conf\r\n    test2-d.conf\r\n  /etc/systemd/system/getty@tty2.service.d/\r\n  /run/systemd/system/getty@tty5.service\r\n```\r\n\r\nThe resulting internal representiation will be as follows.\r\n\r\n```\r\n   top[httpd.service] = /usr/lib/systemd/system/httpd.service\r\n   bottom[httpd.service]\r\n     [/usr/lib/systemd/system/httpd.service] -> env.conf\r\n\r\n   top[postfix.service] = /usr/lib/systemd/system/postfix.service\r\n   bottom[postfix.service]\r\n     [/usr/lib/systemd/system/postfix.service] -> (empty list)\r\n\r\n   top[getty@.service] = /usr/lib/systemd/system/getty@.service\r\n   bottom[getty@.service]\r\n     [/usr/lib/systemd/system/getty@.service]  -> ext.conf\r\n     [/etc/systemd/system/getty@tty1.service]  -> test1-a.conf, test1-b.conf\r\n     [/etc/systemd/system/getty@tty2.service]  -> test2-c.conf, test2-d.conf\r\n     [/run/systemd/systemd/getty@tty5.service] -> (empty list)\r\n```\r\n\r\nThe 'top' hashmap contains the filename of the very first unit, which is\r\nconsidered as the basis for extension. It's key is a base name of the\r\nfull path of the unit it holds as its value, or basename of an template\r\nunit.\r\n\r\nThe 'bottom' hashmap holds a hashmap with override-to-extension\r\nmappings and uses the same key as the 'top' hashmap. The extensions are\r\nsaved in a plain string list. Empty list means that there are only\r\noverrides to the corresponding unit in 'top'.","created_at":"2015-09-11T07:54:12Z","updated_at":"2015-09-22T14:35:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9820c2377ea1168e0127dc2e6a5a031f34acabd0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/systemd/systemd/pulls/1244/commits","review_comments_url":"https://api.github.com/repos/systemd/systemd/pulls/1244/comments","review_comment_url":"https://api.github.com/repos/systemd/systemd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/systemd/systemd/issues/1244/comments","statuses_url":"https://api.github.com/repos/systemd/systemd/statuses/30041c46dbbd94cafcf3deafe85260cbb5807273","head":{"label":"jsynacek:delta-v2","ref":"delta-v2","sha":"30041c46dbbd94cafcf3deafe85260cbb5807273","user":{"login":"jsynacek","id":1014564,"avatar_url":"https://avatars.githubusercontent.com/u/1014564?v=3","gravatar_id":"","url":"https://api.github.com/users/jsynacek","html_url":"https://github.com/jsynacek","followers_url":"https://api.github.com/users/jsynacek/followers","following_url":"https://api.github.com/users/jsynacek/following{/other_user}","gists_url":"https://api.github.com/users/jsynacek/gists{/gist_id}","starred_url":"https://api.github.com/users/jsynacek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsynacek/subscriptions","organizations_url":"https://api.github.com/users/jsynacek/orgs","repos_url":"https://api.github.com/users/jsynacek/repos","events_url":"https://api.github.com/users/jsynacek/events{/privacy}","received_events_url":"https://api.github.com/users/jsynacek/received_events","type":"User","site_admin":false},"repo":{"id":37580630,"name":"systemd","full_name":"jsynacek/systemd","owner":{"login":"jsynacek","id":1014564,"avatar_url":"https://avatars.githubusercontent.com/u/1014564?v=3","gravatar_id":"","url":"https://api.github.com/users/jsynacek","html_url":"https://github.com/jsynacek","followers_url":"https://api.github.com/users/jsynacek/followers","following_url":"https://api.github.com/users/jsynacek/following{/other_user}","gists_url":"https://api.github.com/users/jsynacek/gists{/gist_id}","starred_url":"https://api.github.com/users/jsynacek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsynacek/subscriptions","organizations_url":"https://api.github.com/users/jsynacek/orgs","repos_url":"https://api.github.com/users/jsynacek/repos","events_url":"https://api.github.com/users/jsynacek/events{/privacy}","received_events_url":"https://api.github.com/users/jsynacek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jsynacek/systemd","description":"systemd upstream","fork":true,"url":"https://api.github.com/repos/jsynacek/systemd","forks_url":"https://api.github.com/repos/jsynacek/systemd/forks","keys_url":"https://api.github.com/repos/jsynacek/systemd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jsynacek/systemd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jsynacek/systemd/teams","hooks_url":"https://api.github.com/repos/jsynacek/systemd/hooks","issue_events_url":"https://api.github.com/repos/jsynacek/systemd/issues/events{/number}","events_url":"https://api.github.com/repos/jsynacek/systemd/events","assignees_url":"https://api.github.com/repos/jsynacek/systemd/assignees{/user}","branches_url":"https://api.github.com/repos/jsynacek/systemd/branches{/branch}","tags_url":"https://api.github.com/repos/jsynacek/systemd/tags","blobs_url":"https://api.github.com/repos/jsynacek/systemd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jsynacek/systemd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jsynacek/systemd/git/refs{/sha}","trees_url":"https://api.github.com/repos/jsynacek/systemd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jsynacek/systemd/statuses/{sha}","languages_url":"https://api.github.com/repos/jsynacek/systemd/languages","stargazers_url":"https://api.github.com/repos/jsynacek/systemd/stargazers","contributors_url":"https://api.github.com/repos/jsynacek/systemd/contributors","subscribers_url":"https://api.github.com/repos/jsynacek/systemd/subscribers","subscription_url":"https://api.github.com/repos/jsynacek/systemd/subscription","commits_url":"https://api.github.com/repos/jsynacek/systemd/commits{/sha}","git_commits_url":"https://api.github.com/repos/jsynacek/systemd/git/commits{/sha}","comments_url":"https://api.github.com/repos/jsynacek/systemd/comments{/number}","issue_comment_url":"https://api.github.com/repos/jsynacek/systemd/issues/comments{/number}","contents_url":"https://api.github.com/repos/jsynacek/systemd/contents/{+path}","compare_url":"https://api.github.com/repos/jsynacek/systemd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jsynacek/systemd/merges","archive_url":"https://api.github.com/repos/jsynacek/systemd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jsynacek/systemd/downloads","issues_url":"https://api.github.com/repos/jsynacek/systemd/issues{/number}","pulls_url":"https://api.github.com/repos/jsynacek/systemd/pulls{/number}","milestones_url":"https://api.github.com/repos/jsynacek/systemd/milestones{/number}","notifications_url":"https://api.github.com/repos/jsynacek/systemd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jsynacek/systemd/labels{/name}","releases_url":"https://api.github.com/repos/jsynacek/systemd/releases{/id}","created_at":"2015-06-17T07:51:04Z","updated_at":"2015-06-17T07:51:10Z","pushed_at":"2015-09-22T12:11:43Z","git_url":"git://github.com/jsynacek/systemd.git","ssh_url":"git@github.com:jsynacek/systemd.git","clone_url":"https://github.com/jsynacek/systemd.git","svn_url":"https://github.com/jsynacek/systemd","homepage":"http://www.freedesktop.org/wiki/Software/systemd/","size":41287,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"systemd:master","ref":"master","sha":"3227b2bced36940554e3cefb6b995623227de822","user":{"login":"systemd","id":1918868,"avatar_url":"https://avatars.githubusercontent.com/u/1918868?v=3","gravatar_id":"","url":"https://api.github.com/users/systemd","html_url":"https://github.com/systemd","followers_url":"https://api.github.com/users/systemd/followers","following_url":"https://api.github.com/users/systemd/following{/other_user}","gists_url":"https://api.github.com/users/systemd/gists{/gist_id}","starred_url":"https://api.github.com/users/systemd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/systemd/subscriptions","organizations_url":"https://api.github.com/users/systemd/orgs","repos_url":"https://api.github.com/users/systemd/repos","events_url":"https://api.github.com/users/systemd/events{/privacy}","received_events_url":"https://api.github.com/users/systemd/received_events","type":"Organization","site_admin":false},"repo":{"id":32873313,"name":"systemd","full_name":"systemd/systemd","owner":{"login":"systemd","id":1918868,"avatar_url":"https://avatars.githubusercontent.com/u/1918868?v=3","gravatar_id":"","url":"https://api.github.com/users/systemd","html_url":"https://github.com/systemd","followers_url":"https://api.github.com/users/systemd/followers","following_url":"https://api.github.com/users/systemd/following{/other_user}","gists_url":"https://api.github.com/users/systemd/gists{/gist_id}","starred_url":"https://api.github.com/users/systemd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/systemd/subscriptions","organizations_url":"https://api.github.com/users/systemd/orgs","repos_url":"https://api.github.com/users/systemd/repos","events_url":"https://api.github.com/users/systemd/events{/privacy}","received_events_url":"https://api.github.com/users/systemd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/systemd/systemd","description":"systemd upstream","fork":false,"url":"https://api.github.com/repos/systemd/systemd","forks_url":"https://api.github.com/repos/systemd/systemd/forks","keys_url":"https://api.github.com/repos/systemd/systemd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/systemd/systemd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/systemd/systemd/teams","hooks_url":"https://api.github.com/repos/systemd/systemd/hooks","issue_events_url":"https://api.github.com/repos/systemd/systemd/issues/events{/number}","events_url":"https://api.github.com/repos/systemd/systemd/events","assignees_url":"https://api.github.com/repos/systemd/systemd/assignees{/user}","branches_url":"https://api.github.com/repos/systemd/systemd/branches{/branch}","tags_url":"https://api.github.com/repos/systemd/systemd/tags","blobs_url":"https://api.github.com/repos/systemd/systemd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/systemd/systemd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/systemd/systemd/git/refs{/sha}","trees_url":"https://api.github.com/repos/systemd/systemd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/systemd/systemd/statuses/{sha}","languages_url":"https://api.github.com/repos/systemd/systemd/languages","stargazers_url":"https://api.github.com/repos/systemd/systemd/stargazers","contributors_url":"https://api.github.com/repos/systemd/systemd/contributors","subscribers_url":"https://api.github.com/repos/systemd/systemd/subscribers","subscription_url":"https://api.github.com/repos/systemd/systemd/subscription","commits_url":"https://api.github.com/repos/systemd/systemd/commits{/sha}","git_commits_url":"https://api.github.com/repos/systemd/systemd/git/commits{/sha}","comments_url":"https://api.github.com/repos/systemd/systemd/comments{/number}","issue_comment_url":"https://api.github.com/repos/systemd/systemd/issues/comments{/number}","contents_url":"https://api.github.com/repos/systemd/systemd/contents/{+path}","compare_url":"https://api.github.com/repos/systemd/systemd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/systemd/systemd/merges","archive_url":"https://api.github.com/repos/systemd/systemd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/systemd/systemd/downloads","issues_url":"https://api.github.com/repos/systemd/systemd/issues{/number}","pulls_url":"https://api.github.com/repos/systemd/systemd/pulls{/number}","milestones_url":"https://api.github.com/repos/systemd/systemd/milestones{/number}","notifications_url":"https://api.github.com/repos/systemd/systemd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/systemd/systemd/labels{/name}","releases_url":"https://api.github.com/repos/systemd/systemd/releases{/id}","created_at":"2015-03-25T15:27:27Z","updated_at":"2015-09-22T02:00:31Z","pushed_at":"2015-09-22T14:18:34Z","git_url":"git://github.com/systemd/systemd.git","ssh_url":"git@github.com:systemd/systemd.git","clone_url":"https://github.com/systemd/systemd.git","svn_url":"https://github.com/systemd/systemd","homepage":"http://www.freedesktop.org/wiki/Software/systemd/","size":51279,"stargazers_count":571,"watchers_count":571,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":196,"mirror_url":null,"open_issues_count":179,"forks":196,"open_issues":179,"watchers":571,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/systemd/systemd/pulls/1244"},"html":{"href":"https://github.com/systemd/systemd/pull/1244"},"issue":{"href":"https://api.github.com/repos/systemd/systemd/issues/1244"},"comments":{"href":"https://api.github.com/repos/systemd/systemd/issues/1244/comments"},"review_comments":{"href":"https://api.github.com/repos/systemd/systemd/pulls/1244/comments"},"review_comment":{"href":"https://api.github.com/repos/systemd/systemd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/systemd/systemd/pulls/1244/commits"},"statuses":{"href":"https://api.github.com/repos/systemd/systemd/statuses/30041c46dbbd94cafcf3deafe85260cbb5807273"}}}}