Skip to content
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
This repository was archived by the owner on Dec 2, 2026. It is now read-only.

Diff Memory leaks - Expose git_diff_free #1541

Open

Description

@yelled3

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);
    })
    .then((repoDiff) => {
        return repoDiff.toBuf(git.Diff.FORMAT.PATCH);
    })

This generates a memory leak.

I know the repository needs to be freed using repo.free(): (or repo.cleanup())
https://www.nodegit.org/api/repository/#free

According to the docs:
https://libgit2.org/libgit2/#HEAD/group/repository/git_repository_free

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

Which means I also need to free up the Diff object;
Apparently there's a way to free a diff using git_diff_free
https://libgit2.org/libgit2/#HEAD/group/diff/git_diff_free

But from what I understand nodegit doesn't expose this function, see:

"git_diff_free": {
"ignore": true
},

EDIT
It seems like I also need to free up the Buf I'm creating using repoDiff.toBuf(git.Diff.FORMAT.PATCH);
https://www.nodegit.org/api/buf/#free
https://libgit2.org/libgit2/#HEAD/group/buf/git_buf_free

But I didn't find a way to do this since repoDiff.toBuf return a Promise which returns a string.
It seems the Buf is only available in the C++ implementation. (see NAN_METHOD(GitDiff::ToBuf) )

Is there another way to do this?
Thanks

BTW, I'm guessing this also relates to: #766

Activity

  1. tbranyen commented on Sep 17, 2018

    @tbranyen
    Member

    The Buf you're talking about is separate from freeing the Diff. Couldn't you simply enable the git_diff_free method, by dropping the ignore: true and then passing your repoDiff to git.Diff.free(repoDiff)?

    We could also add free to the repoDiff prototype.

  2. implausible commented on Oct 17, 2018

    @implausible
    Member

    I think this issue should be resolved from #1570.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions