this patch fixes one common, and 4 rare memory leaks in read-tree.c. Ingo
Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]> --- read-tree.c.orig +++ read-tree.c @@ -23,23 +23,27 @@ static int read_one_entry(unsigned char static int read_tree(unsigned char *sha1, const char *base, int baselen) { - void *buffer; + void *buffer0, *buffer; unsigned long size; char type[20]; - buffer = read_sha1_file(sha1, type, &size); + buffer0 = buffer = read_sha1_file(sha1, type, &size); if (!buffer) return -1; - if (strcmp(type, "tree")) + if (strcmp(type, "tree")) { + free(buffer); return -1; + } while (size) { int len = strlen(buffer)+1; unsigned char *sha1 = buffer + len; char *path = strchr(buffer, ' ')+1; unsigned int mode; - if (size < len + 20 || sscanf(buffer, "%o", &mode) != 1) + if (size < len + 20 || sscanf(buffer, "%o", &mode) != 1) { + free(buffer0); return -1; + } buffer = sha1 + 20; size -= len + 20; @@ -53,13 +57,19 @@ static int read_tree(unsigned char *sha1 newbase[baselen + pathlen] = '/'; retval = read_tree(sha1, newbase, baselen + pathlen + 1); free(newbase); - if (retval) + if (retval) { + free(buffer0); return -1; + } continue; } - if (read_one_entry(sha1, base, baselen, path, mode) < 0) + if (read_one_entry(sha1, base, baselen, path, mode) < 0) { + free(buffer0); return -1; + } } + free(buffer0); + return 0; } - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html