cache.c: fix cache_ls
Commit fb3655d
(use struct strbuf instead of static buffers, 2013-04-06)
broke the logic in cache.c::cache_ls by failing to set slot->cache_name
before calling open_slot.
While fixing this, also free the strbufs added by that commit once we're
done with them.
Signed-off-by: John Keeping <john@keeping.me.uk>
This commit is contained in:
parent
7966fd9b8e
commit
f75900b04f
14
cache.c
14
cache.c
@ -316,6 +316,7 @@ int cache_process(int size, const char *path, const char *key, int ttl,
|
|||||||
struct strbuf filename = STRBUF_INIT;
|
struct strbuf filename = STRBUF_INIT;
|
||||||
struct strbuf lockname = STRBUF_INIT;
|
struct strbuf lockname = STRBUF_INIT;
|
||||||
struct cache_slot slot;
|
struct cache_slot slot;
|
||||||
|
int result;
|
||||||
|
|
||||||
/* If the cache is disabled, just generate the content */
|
/* If the cache is disabled, just generate the content */
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
@ -343,11 +344,15 @@ int cache_process(int size, const char *path, const char *key, int ttl,
|
|||||||
slot.fn = fn;
|
slot.fn = fn;
|
||||||
slot.cbdata = cbdata;
|
slot.cbdata = cbdata;
|
||||||
slot.ttl = ttl;
|
slot.ttl = ttl;
|
||||||
slot.cache_name = strbuf_detach(&filename, NULL);
|
slot.cache_name = filename.buf;
|
||||||
slot.lock_name = strbuf_detach(&lockname, NULL);
|
slot.lock_name = lockname.buf;
|
||||||
slot.key = key;
|
slot.key = key;
|
||||||
slot.keylen = strlen(key);
|
slot.keylen = strlen(key);
|
||||||
return process_slot(&slot);
|
result = process_slot(&slot);
|
||||||
|
|
||||||
|
strbuf_release(&filename);
|
||||||
|
strbuf_release(&lockname);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a strftime formatted date/time
|
/* Return a strftime formatted date/time
|
||||||
@ -393,6 +398,7 @@ int cache_ls(const char *path)
|
|||||||
continue;
|
continue;
|
||||||
strbuf_setlen(&fullname, prefixlen);
|
strbuf_setlen(&fullname, prefixlen);
|
||||||
strbuf_addstr(&fullname, ent->d_name);
|
strbuf_addstr(&fullname, ent->d_name);
|
||||||
|
slot.cache_name = fullname.buf;
|
||||||
if ((err = open_slot(&slot)) != 0) {
|
if ((err = open_slot(&slot)) != 0) {
|
||||||
cache_log("[cgit] unable to open path %s: %s (%d)\n",
|
cache_log("[cgit] unable to open path %s: %s (%d)\n",
|
||||||
fullname.buf, strerror(err), err);
|
fullname.buf, strerror(err), err);
|
||||||
@ -406,8 +412,8 @@ int cache_ls(const char *path)
|
|||||||
slot.buf);
|
slot.buf);
|
||||||
close_slot(&slot);
|
close_slot(&slot);
|
||||||
}
|
}
|
||||||
slot.cache_name = strbuf_detach(&fullname, NULL);
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
strbuf_release(&fullname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user