aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar John Keeping <john@keeping.me.uk>2013-05-19 02:28:14 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2013-05-19 02:45:28 (JST)
commitf75900b04f73725c00abb46405b51ade59313ecc (patch)
tree9c7e90aabe09418b43fbb41c99bb4965d1e7e14e
parent7966fd9b8e32562196b52abd32f6ba1e15228b81 (diff)
downloadcgit-f75900b04f73725c00abb46405b51ade59313ecc.zip
cgit-f75900b04f73725c00abb46405b51ade59313ecc.tar.gz
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>
-rw-r--r--cache.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/cache.c b/cache.c
index c1d777b..74a1795 100644
--- a/cache.c
+++ b/cache.c
@@ -316,6 +316,7 @@ int cache_process(int size, const char *path, const char *key, int ttl,
316 struct strbuf filename = STRBUF_INIT; 316 struct strbuf filename = STRBUF_INIT;
317 struct strbuf lockname = STRBUF_INIT; 317 struct strbuf lockname = STRBUF_INIT;
318 struct cache_slot slot; 318 struct cache_slot slot;
319 int result;
319 320
320 /* If the cache is disabled, just generate the content */ 321 /* If the cache is disabled, just generate the content */
321 if (size <= 0) { 322 if (size <= 0) {
@@ -343,11 +344,15 @@ int cache_process(int size, const char *path, const char *key, int ttl,
343 slot.fn = fn; 344 slot.fn = fn;
344 slot.cbdata = cbdata; 345 slot.cbdata = cbdata;
345 slot.ttl = ttl; 346 slot.ttl = ttl;
346 slot.cache_name = strbuf_detach(&filename, NULL); 347 slot.cache_name = filename.buf;
347 slot.lock_name = strbuf_detach(&lockname, NULL); 348 slot.lock_name = lockname.buf;
348 slot.key = key; 349 slot.key = key;
349 slot.keylen = strlen(key); 350 slot.keylen = strlen(key);
350 return process_slot(&slot); 351 result = process_slot(&slot);
352
353 strbuf_release(&filename);
354 strbuf_release(&lockname);
355 return result;
351} 356}
352 357
353/* Return a strftime formatted date/time 358/* Return a strftime formatted date/time
@@ -393,6 +398,7 @@ int cache_ls(const char *path)
393 continue; 398 continue;
394 strbuf_setlen(&fullname, prefixlen); 399 strbuf_setlen(&fullname, prefixlen);
395 strbuf_addstr(&fullname, ent->d_name); 400 strbuf_addstr(&fullname, ent->d_name);
401 slot.cache_name = fullname.buf;
396 if ((err = open_slot(&slot)) != 0) { 402 if ((err = open_slot(&slot)) != 0) {
397 cache_log("[cgit] unable to open path %s: %s (%d)\n", 403 cache_log("[cgit] unable to open path %s: %s (%d)\n",
398 fullname.buf, strerror(err), err); 404 fullname.buf, strerror(err), err);
@@ -406,8 +412,8 @@ int cache_ls(const char *path)
406 slot.buf); 412 slot.buf);
407 close_slot(&slot); 413 close_slot(&slot);
408 } 414 }
409 slot.cache_name = strbuf_detach(&fullname, NULL);
410 closedir(dir); 415 closedir(dir);
416 strbuf_release(&fullname);
411 return 0; 417 return 0;
412} 418}
413 419