diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2008-12-30 23:21:36 -0800 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2008-12-30 23:28:30 -0800 |
commit | 64a47c01426a36cdb7e598d17018d5791e54bb97 (patch) | |
tree | c96d985df9957e7c042290d868d44feed8a4fc08 /src/errors.c | |
parent | ffb55c532ccc1cb3c47eeeaac6c64240ab88fe29 (diff) | |
download | libgit2-64a47c01426a36cdb7e598d17018d5791e54bb97.tar.gz |
Wrap malloc and friends and report out of memory as GIT_ENOMEM
We now forbid direct use of malloc, strdup or calloc within the
library and instead use wrapper functions git__malloc, etc. to
invoke the underlying library malloc and set git_errno to a no
memory error code if the allocation fails.
In the future once we have pack objects in memory we are likely
to enhance these routines with garbage collection logic to purge
cached pack data when allocations fail. Because the size of the
function will grow somewhat large, we don't want to mark them for
inline as gcc tends to aggressively inline, creating larger than
expected executables.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/errors.c')
-rw-r--r-- | src/errors.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/errors.c b/src/errors.c index 75636f477..deb106bfd 100644 --- a/src/errors.c +++ b/src/errors.c @@ -19,7 +19,9 @@ int *git__errno_storage(void) { int *e = pthread_getspecific(errno_key); if (!e) { +#undef calloc e = calloc(1, sizeof(*e)); +#define calloc(a,b) GIT__FORBID_MALLOC pthread_setspecific(errno_key, e); } return e; @@ -33,6 +35,7 @@ static struct { } error_codes[] = { { GIT_ENOTOID, "Not a git oid" }, { GIT_ENOTFOUND, "Object does not exist in the scope searched" }, + { GIT_ENOMEM, "Not enough space" }, }; const char *git_strerror(int num) |