{"comment":{"url":"https://api.github.com/repos/bmc/daemonize/comments/14936789","html_url":"https://github.com/bmc/daemonize/commit/4e756f73e50190475554804c54cd3344e8ecc103#commitcomment-14936789","id":14936789,"user":{"login":"andy-js","id":1582704,"avatar_url":"https://avatars.githubusercontent.com/u/1582704?v=3","gravatar_id":"","url":"https://api.github.com/users/andy-js","html_url":"https://github.com/andy-js","followers_url":"https://api.github.com/users/andy-js/followers","following_url":"https://api.github.com/users/andy-js/following{/other_user}","gists_url":"https://api.github.com/users/andy-js/gists{/gist_id}","starred_url":"https://api.github.com/users/andy-js/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andy-js/subscriptions","organizations_url":"https://api.github.com/users/andy-js/orgs","repos_url":"https://api.github.com/users/andy-js/repos","events_url":"https://api.github.com/users/andy-js/events{/privacy}","received_events_url":"https://api.github.com/users/andy-js/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"4e756f73e50190475554804c54cd3344e8ecc103","created_at":"2015-12-11T22:40:26Z","updated_at":"2015-12-11T22:40:26Z","body":"Slightly shorter and perhaps less portable version:\r\n\r\n<pre>\r\ndiff --git a/daemonize.c b/daemonize.c\r\nindex 6c968bc..d580cfc 100644\r\n--- a/daemonize.c\r\n+++ b/daemonize.c\r\n@@ -147,11 +147,8 @@ static void add_to_env(char opt, const char *envvar)\r\n     int name_len = (int) (eq - envvar);\r\n     int val_len  = (strlen(envvar) - name_len) - 1;\r\n \r\n-    char *name = (char *) malloc(name_len + 1);\r\n-    char *value = (char *) malloc(val_len + 1);\r\n-    (void) strncat(name, envvar, name_len);\r\n-    eq++;\r\n-    (void) strncat(value, eq, val_len);\r\n+    char *name = strndupa(envvar, name_len);\r\n+    char *value = strndupa(eq + 1, val_len);\r\n     setenv(name, value, 1);\r\n }\r\n \r\n</pre>"}}