Code

connect.c: guard config parser from value=NULL
[git.git] / builtin-pack-objects.c
index e0ce114be7f65307da96bc620d5fb8902b793c73..4113f013cfae060cc21719a421e98d1741752f9b 100644 (file)
@@ -445,7 +445,7 @@ static unsigned long write_object(struct sha1file *f,
                        /* nothing */;
                deflateEnd(&stream);
                datalen = stream.total_out;
-               deflateEnd(&stream);
+
                /*
                 * The object header is a byte of 'type' followed by zero or
                 * more bytes of length.
@@ -1464,7 +1464,7 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n)
        return m;
 }
 
-static unsigned long free_unpacked(struct unpacked *n)
+static unsigned long free_unpacked_data(struct unpacked *n)
 {
        unsigned long freed_mem = sizeof_delta_index(n->index);
        free_delta_index(n->index);
@@ -1474,6 +1474,12 @@ static unsigned long free_unpacked(struct unpacked *n)
                free(n->data);
                n->data = NULL;
        }
+       return freed_mem;
+}
+
+static unsigned long free_unpacked(struct unpacked *n)
+{
+       unsigned long freed_mem = free_unpacked_data(n);
        n->entry = NULL;
        n->depth = 0;
        return freed_mem;
@@ -1514,7 +1520,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
                       mem_usage > window_memory_limit &&
                       count > 1) {
                        uint32_t tail = (idx + window - count) % window;
-                       mem_usage -= free_unpacked(array + tail);
+                       mem_usage -= free_unpacked_data(array + tail);
                        count--;
                }
 
@@ -1547,6 +1553,9 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
                        if (!m->entry)
                                break;
                        ret = try_delta(n, m, max_depth, &mem_usage);
+                       if (window_memory_limit &&
+                           mem_usage > window_memory_limit)
+                               mem_usage -= free_unpacked_data(m);
                        if (ret < 0)
                                break;
                        else if (ret > 0)
@@ -1672,7 +1681,8 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
                p[i].data_ready = 0;
 
                /* try to split chunks on "path" boundaries */
-               while (sub_size < list_size && list[sub_size]->hash &&
+               while (sub_size && sub_size < list_size &&
+                      list[sub_size]->hash &&
                       list[sub_size]->hash == list[sub_size-1]->hash)
                        sub_size++;
 
@@ -2013,7 +2023,7 @@ static void get_object_list(int ac, const char **av)
 
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
-               if (line[len - 1] == '\n')
+               if (len && line[len - 1] == '\n')
                        line[--len] = 0;
                if (!len)
                        break;