Skip to content
This repository was archived by the owner on Sep 28, 2023. It is now read-only.

Commit cb9c269

Browse files
committed
Do not do internal item_realloc() every time
refcount == 2 is "linked and I own it" code was doing a replace if refcount != 1 (which would mean unlinked and I own it, in this case. If that code ever actually misfired some weird stuff might happen).
1 parent 368b82a commit cb9c269

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

items.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ void do_item_unlink_nolock(item *it, const uint32_t hv) {
345345
void do_item_remove(item *it) {
346346
MEMCACHED_ITEM_REMOVE(ITEM_key(it), it->nkey, it->nbytes);
347347
assert((it->it_flags & ITEM_SLABBED) == 0);
348+
assert(it->refcount > 0);
348349

349350
if (refcount_decr(&it->refcount) == 0) {
350351
item_free(it);

memcached.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3162,7 +3162,9 @@ enum delta_result_type do_add_delta(conn *c, const char *key, const size_t nkey,
31623162

31633163
snprintf(buf, INCR_MAX_STORAGE_LEN, "%llu", (unsigned long long)value);
31643164
res = strlen(buf);
3165-
if (res + 2 > it->nbytes || it->refcount != 1) { /* need to realloc */
3165+
/* refcount == 2 means we are the only ones holding the item, and it is
3166+
* linked. */
3167+
if (res + 2 > it->nbytes || it->refcount != 2) { /* need to realloc */
31663168
item *new_it;
31673169
new_it = do_item_alloc(ITEM_key(it), it->nkey, atoi(ITEM_suffix(it) + 1), it->exptime, res + 2, hv);
31683170
if (new_it == 0) {

0 commit comments

Comments
 (0)