add_to_index(): free unused cache-entry
[gitweb.git] / read-cache.c
index 60abec6055342d7a8c317b02bccaa881eb9e4540..5b922fd583317335b75a428de84420f2f7f4eb3c 100644 (file)
@@ -707,9 +707,11 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                    ce->ce_mode == alias->ce_mode);
 
        if (pretend)
-               ;
-       else if (add_index_entry(istate, ce, add_option))
-               return error("unable to add %s to index",path);
+               free(ce);
+       else if (add_index_entry(istate, ce, add_option)) {
+               free(ce);
+               return error("unable to add %s to index", path);
+       }
        if (verbose && !was_same)
                printf("add '%s'\n", path);
        return 0;