Title: Diff Memory leaks - Expose git_diff_free · Issue #1541 · nodegit/nodegit · GitHub
Open Graph Title: Diff Memory leaks - Expose git_diff_free · Issue #1541 · nodegit/nodegit
X Title: Diff Memory leaks - Expose git_diff_free · Issue #1541 · nodegit/nodegit
Description: I'm running a script that check a repo for Diff.indexToWorkdir every interval, like so: // runs in interval every 1s .then(() => { return git.Repository.open('../my_repo_path'); }) .then( (repo) => { return git.Diff.indexToWorkdir(repo);...
Open Graph Description: I'm running a script that check a repo for Diff.indexToWorkdir every interval, like so: // runs in interval every 1s .then(() => { return git.Repository.open('../my_repo_path'); }) .then( (repo) =>...
X Description: I'm running a script that check a repo for Diff.indexToWorkdir every interval, like so: // runs in interval every 1s .then(() => { return git.Repository.open('../my_repo_path'); }) ....
Opengraph URL: https://github.com/nodegit/nodegit/issues/1541
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Diff Memory leaks - Expose git_diff_free","articleBody":"I'm running a script that check a repo for `Diff.indexToWorkdir` every interval, like so:\r\n```js\r\n // runs in interval every 1s\r\n .then(() =\u003e {\r\n return git.Repository.open('../my_repo_path');\r\n })\r\n .then( (repo) =\u003e {\r\n return git.Diff.indexToWorkdir(repo);\r\n })\r\n .then((repoDiff) =\u003e {\r\n return repoDiff.toBuf(git.Diff.FORMAT.PATCH);\r\n })\r\n```\r\nThis generates a memory leak.\r\n\r\nI know the repository needs to be freed using `repo.free()`: (or `repo.cleanup()`)\r\nhttps://www.nodegit.org/api/repository/#free\r\n\r\nAccording to the docs:\r\nhttps://libgit2.org/libgit2/#HEAD/group/repository/git_repository_free\r\n\r\n\u003e Note that after a repository is free'd, all the objects it has spawned **will still exist until they are manually closed by the user with git_object_free**, but accessing any of the attributes of an object without a backing repository will result in undefined behavior\r\n\r\nWhich means I also need to free up the Diff object;\r\nApparently there's a way to free a diff using `git_diff_free`\r\nhttps://libgit2.org/libgit2/#HEAD/group/diff/git_diff_free\r\n\r\nBut from what I understand nodegit doesn't expose this function, see:\r\nhttps://github.com/nodegit/nodegit/blob/c944ec6ae5c8fffbac8db7b1f0180ae1254560f2/generate/input/descriptor.json#L933-L935\r\n\r\n**EDIT**\r\nIt seems like I also need to free up the `Buf` I'm creating using `repoDiff.toBuf(git.Diff.FORMAT.PATCH);`\r\nhttps://www.nodegit.org/api/buf/#free\r\nhttps://libgit2.org/libgit2/#HEAD/group/buf/git_buf_free\r\n\r\nBut I didn't find a way to do this since `repoDiff.toBuf` return a Promise which returns a string.\r\nIt seems the `Buf` is only available in the C++ implementation. (see NAN_METHOD(GitDiff::ToBuf) )\r\n\r\nIs there another way to do this?\r\nThanks\r\n\r\nBTW, I'm guessing this also relates to: https://github.com/nodegit/nodegit/issues/766","author":{"url":"https://github.com/yelled3","@type":"Person","name":"yelled3"},"datePublished":"2018-08-21T13:44:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/1541/nodegit/issues/1541"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c59c6944-1184-57e0-a349-d2cd2ebf760d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95B4:C5156:F0C91:14695D:6A5FE73D |
| html-safe-nonce | ee90ae7d24d419d846c2ec6f0edc50213a21da70c188d84f4f66889212c3c30d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUI0OkM1MTU2OkYwQzkxOjE0Njk1RDo2QTVGRTczRCIsInZpc2l0b3JfaWQiOiIxMjE0ODg2NDcyNzQ0NjkxNTE3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3f085d7628b722432e77f5213a621606f2f78db773fcbbe43e9150ce3e61e095 |
| hovercard-subject-tag | issue:352544419 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodegit/nodegit/1541/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bffc2d8b6e1ff7caf1ae8a7d18de4e92ae7d0d36d6ec7cc302290507f0b86657/nodegit/nodegit/issues/1541 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bffc2d8b6e1ff7caf1ae8a7d18de4e92ae7d0d36d6ec7cc302290507f0b86657/nodegit/nodegit/issues/1541 |
| og:image:alt | I'm running a script that check a repo for Diff.indexToWorkdir every interval, like so: // runs in interval every 1s .then(() => { return git.Repository.open('../my_repo_path'); }) .then( (repo) =>... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yelled3 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 78938542173c0d8e4ad1aefc7954896e81c10ce2620286603ef14cf593bd5a11 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodegit/nodegit git https://github.com/nodegit/nodegit.git |
| octolytics-dimension-user_id | 657068 |
| octolytics-dimension-user_login | nodegit |
| octolytics-dimension-repository_id | 1383170 |
| octolytics-dimension-repository_nwo | nodegit/nodegit |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1383170 |
| octolytics-dimension-repository_network_root_nwo | nodegit/nodegit |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1a427601e09953033b696253e754ebc7328096a7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width