summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 00829b5)
raw | patch | inline | side by side (parent: 00829b5)
author | Junio C Hamano <junkio@cox.net> | |
Mon, 18 Apr 2005 22:07:24 +0000 (15:07 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Mon, 18 Apr 2005 22:07:24 +0000 (15:07 -0700) |
This patch fixes sq_expand() and show_differences() not to use and
hold onto its privately allocated buffer, which was a misguided
attempt to reduce calls to malloc but made later changes harder.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
hold onto its privately allocated buffer, which was a misguided
attempt to reduce calls to malloc but made later changes harder.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
show-diff.c | patch | blob | history |
diff --git a/show-diff.c b/show-diff.c
index 36afb3cc91305c35d2d811be61b308c14fb1a63d..2bd789c261851e899bdf653c1fa59d39412c6f51 100644 (file)
--- a/show-diff.c
+++ b/show-diff.c
static char *sq_expand(char *src)
{
static char *buf = NULL;
- static int buf_size = -1;
int cnt, c;
char *cp;
if (*cp == '\'')
cnt += 3;
- if (buf_size < cnt) {
- free(buf);
- buf_size = cnt;
- buf = malloc(cnt);
- }
-
+ if (! (buf = malloc(cnt)))
+ return buf;
cp = buf;
while ((c = *src++)) {
if (c != '\'')
unsigned long long old_size)
{
FILE *f;
- static char *cmd = NULL;
- static int cmd_size = -1;
-
char *name_sq = sq_expand(name);
- int cmd_required_length = strlen(name_sq) * 2 + strlen(diff_cmd);
+ int cmd_size = strlen(name_sq) * 2 + strlen(diff_cmd);
+ char *cmd = malloc(cmd_size);
- if (cmd_size < cmd_required_length) {
- free(cmd);
- cmd_size = cmd_required_length;
- cmd = malloc(cmd_required_length);
- }
snprintf(cmd, cmd_size, diff_cmd, name_sq, name_sq);
f = popen(cmd, "w");
if (old_size)
fwrite(old_contents, old_size, 1, f);
pclose(f);
+ free(name_sq);
+ free(cmd);
}
static void show_diff_empty(struct cache_entry *ce)