{"action":"created","issue":{"url":"https://api.github.com/repos/nodegit/nodegit/issues/823","labels_url":"https://api.github.com/repos/nodegit/nodegit/issues/823/labels{/name}","comments_url":"https://api.github.com/repos/nodegit/nodegit/issues/823/comments","events_url":"https://api.github.com/repos/nodegit/nodegit/issues/823/events","html_url":"https://github.com/nodegit/nodegit/issues/823","id":121361027,"number":823,"title":"Segmentation Fault","user":{"login":"ChristianMurphy","id":3107513,"avatar_url":"https://avatars.githubusercontent.com/u/3107513?v=3","gravatar_id":"","url":"https://api.github.com/users/ChristianMurphy","html_url":"https://github.com/ChristianMurphy","followers_url":"https://api.github.com/users/ChristianMurphy/followers","following_url":"https://api.github.com/users/ChristianMurphy/following{/other_user}","gists_url":"https://api.github.com/users/ChristianMurphy/gists{/gist_id}","starred_url":"https://api.github.com/users/ChristianMurphy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChristianMurphy/subscriptions","organizations_url":"https://api.github.com/users/ChristianMurphy/orgs","repos_url":"https://api.github.com/users/ChristianMurphy/repos","events_url":"https://api.github.com/users/ChristianMurphy/events{/privacy}","received_events_url":"https://api.github.com/users/ChristianMurphy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-09T23:00:14Z","updated_at":"2015-12-17T19:49:47Z","closed_at":null,"body":"I'm using NodeGit to setup multiple git repositories.\r\nWhen I do that I get the error:\r\n``` log\r\n[1]    7896 segmentation fault (core dumped)  node example.js\r\n```\r\nThis error happens with NodeGit 0.5.0 and 0.6.0.\r\nRunning on Ubuntu 15.10, on Node JS 5.2.0 and 4.3.2\r\n\r\nHere is the code I am trying to run.\r\nThis will work correctly with a single destination, but will SegFault with multiple.\r\nA version of this code previously worked with multiple destinations with NodeGit 0.4.0\r\n``` javascript\r\n'use strict';\r\n\r\nconst NodeGit = require('nodegit');\r\nconst path = require('path');\r\n\r\nconst temporaryFolder = path.join(__dirname, 'temp');\r\nconst branchReference = 'refs/heads/master:refs/heads/master';\r\n\r\n// replace this with your own username and password\r\n// seedRepository should have files already\r\n// destinationRepositories should not have any files or commits yet\r\nseedRepositories('testUser', 'password', 'https://github.com/ChristianMurphy/just-a-test-ignore-this', ['https://github.com/ChristianMurphy/please-work-1', 'https://github.com/ChristianMurphy/please-work-2'])\r\n\r\nfunction seedRepositories (username, password, seedRepositoryURL, destinationRepositoryURLs) {\r\n    const credentials = NodeGit.Cred.userpassPlaintextNew(username, password);\r\n\r\n    // clone seed repo\r\n    NodeGit.Clone(seedRepositoryURL, temporaryFolder, {\r\n        callbacks: {\r\n            credentials: function () {\r\n                return credentials;\r\n            }\r\n        }\r\n    })\r\n    // open the repository\r\n    .then(() => {\r\n        return NodeGit.Repository.open(temporaryFolder);\r\n    })\r\n    // push the seed repository to all destination repositories\r\n    .then((seedRepository) => {\r\n        const promises = [];\r\n\r\n        // for each destination\r\n        for (let index = 0; index < destinationRepositoryURLs.length; index++) {\r\n            // create a remote for destination\r\n            NodeGit.Remote.create(seedRepository, index.toString(), destinationRepositoryURLs[index]);\r\n            // open remote for destination and collect resulting promise\r\n            promises.push(\r\n                NodeGit.Remote.lookup(seedRepository, index.toString())\r\n                .then((remote) => {\r\n                    // push to destination remote\r\n                    return remote.push([branchReference], {\r\n                        callbacks: {\r\n                            credentials: function () {\r\n                                return credentials;\r\n                            }\r\n                        }\r\n                    });\r\n                })\r\n            );\r\n        }\r\n        // wait for all pushes to complete\r\n        return Promise.all(promises);\r\n    })\r\n    .catch((err) => {\r\n        console.error(err);\r\n    });\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/nodegit/nodegit/issues/comments/165563420","html_url":"https://github.com/nodegit/nodegit/issues/823#issuecomment-165563420","issue_url":"https://api.github.com/repos/nodegit/nodegit/issues/823","id":165563420,"user":{"login":"ChristianMurphy","id":3107513,"avatar_url":"https://avatars.githubusercontent.com/u/3107513?v=3","gravatar_id":"","url":"https://api.github.com/users/ChristianMurphy","html_url":"https://github.com/ChristianMurphy","followers_url":"https://api.github.com/users/ChristianMurphy/followers","following_url":"https://api.github.com/users/ChristianMurphy/following{/other_user}","gists_url":"https://api.github.com/users/ChristianMurphy/gists{/gist_id}","starred_url":"https://api.github.com/users/ChristianMurphy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChristianMurphy/subscriptions","organizations_url":"https://api.github.com/users/ChristianMurphy/orgs","repos_url":"https://api.github.com/users/ChristianMurphy/repos","events_url":"https://api.github.com/users/ChristianMurphy/events{/privacy}","received_events_url":"https://api.github.com/users/ChristianMurphy/received_events","type":"User","site_admin":false},"created_at":"2015-12-17T19:49:47Z","updated_at":"2015-12-17T19:49:47Z","body":"Update.\r\nI tried using promise chaining instead of promise all.\r\nNow instead of `Segmentation Fault`\r\nIt errors with `*** Error in 'node': double free or corruption (fasttop): 0x0000000001c80ac0 ***`\r\n\r\nHere is the updated code.\r\n``` js\r\n'use strict';\r\n\r\nconst NodeGit = require('nodegit');\r\nconst path = require('path');\r\n\r\nconst temporaryFolder = path.join(__dirname, 'temp');\r\nconst branchReference = 'refs/heads/master:refs/heads/master';\r\n\r\n// replace this with your own username and password\r\n// seedRepository should have files already\r\n// destinationRepositories should not have any files or commits yet\r\nseedRepositories('testUser', 'password', 'https://github.com/ChristianMurphy/just-a-test-ignore-this', ['https://github.com/ChristianMurphy/please-work-1', 'https://github.com/ChristianMurphy/please-work-2'])\r\n\r\nfunction seedRepositories (username, password, seedRepositoryURL, destinationRepositoryURLs) {\r\n    const credentials = NodeGit.Cred.userpassPlaintextNew(username, password);\r\n\r\n    // clone seed repo\r\n    NodeGit.Clone(seedRepositoryURL, temporaryFolder, {\r\n        callbacks: {\r\n            credentials: function () {\r\n                return credentials;\r\n            }\r\n        }\r\n    })\r\n    // open the repository\r\n    .then(() => {\r\n        return NodeGit.Repository.open(temporaryFolder);\r\n    })\r\n    // push the seed repository to all destination repositories\r\n    .then((seedRepository) => {\r\n        const chain = Promise.resolve();\r\n\r\n        // for each destination\r\n        for (let index = 0; index < destinationRepositoryURLs.length; index += 1) {\r\n            // create a remote for destination\r\n            NodeGit.Remote.create(seedRepository, index.toString(), destinationRepositoryURLs[index]);\r\n            // open remote for destination\r\n            chain.then(\r\n                NodeGit.Remote.lookup(seedRepository, index.toString())\r\n            );\r\n            // push to the remote\r\n            chain.then((remote) => {\r\n                // push to destination remote\r\n                return remote.push([branchReference], {\r\n                    callbacks: {\r\n                        credentials () {\r\n                            return credentials;\r\n                        }\r\n                    }\r\n                });\r\n            });\r\n        }\r\n        // wait for all pushes to complete\r\n        return chain;\r\n    })\r\n    .catch((err) => {\r\n        console.error(err);\r\n    });\r\n};\r\n```"}}