Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
121796f7
Commit
121796f7
authored
Nov 04, 2009
by
root
Browse files
fixed a refcounting bug with SORT ... STORE leading to random crashes
parent
d0ccebcf
Changes
2
Hide whitespace changes
Inline
Side-by-side
dict.c
View file @
121796f7
...
@@ -226,7 +226,10 @@ int dictAdd(dict *ht, void *key, void *val)
...
@@ -226,7 +226,10 @@ int dictAdd(dict *ht, void *key, void *val)
return
DICT_OK
;
return
DICT_OK
;
}
}
/* Add an element, discarding the old if the key already exists */
/* Add an element, discarding the old if the key already exists.
* Return 1 if the key was added from scratch, 0 if there was already an
* element with such key and dictReplace() just performed a value update
* operation. */
int
dictReplace
(
dict
*
ht
,
void
*
key
,
void
*
val
)
int
dictReplace
(
dict
*
ht
,
void
*
key
,
void
*
val
)
{
{
dictEntry
*
entry
;
dictEntry
*
entry
;
...
@@ -234,13 +237,13 @@ int dictReplace(dict *ht, void *key, void *val)
...
@@ -234,13 +237,13 @@ int dictReplace(dict *ht, void *key, void *val)
/* Try to add the element. If the key
/* Try to add the element. If the key
* does not exists dictAdd will suceed. */
* does not exists dictAdd will suceed. */
if
(
dictAdd
(
ht
,
key
,
val
)
==
DICT_OK
)
if
(
dictAdd
(
ht
,
key
,
val
)
==
DICT_OK
)
return
DICT_OK
;
return
1
;
/* It already exists, get the entry */
/* It already exists, get the entry */
entry
=
dictFind
(
ht
,
key
);
entry
=
dictFind
(
ht
,
key
);
/* Free the old value and set the new one */
/* Free the old value and set the new one */
dictFreeEntryVal
(
ht
,
entry
);
dictFreeEntryVal
(
ht
,
entry
);
dictSetHashVal
(
ht
,
entry
,
val
);
dictSetHashVal
(
ht
,
entry
,
val
);
return
DICT_OK
;
return
0
;
}
}
/* Search and remove an element */
/* Search and remove an element */
...
...
redis.c
View file @
121796f7
...
@@ -4664,7 +4664,9 @@ static void sortCommand(redisClient *c) {
...
@@ -4664,7 +4664,9 @@ static void sortCommand(redisClient *c) {
}
}
}
}
}
}
dictReplace
(
c
->
db
->
dict
,
storekey
,
listObject
);
if
(
dictReplace
(
c
->
db
->
dict
,
storekey
,
listObject
))
{
incrRefCount
(
storekey
);
}
/* Note: we add 1 because the DB is dirty anyway since even if the
/* Note: we add 1 because the DB is dirty anyway since even if the
* SORT result is empty a new key is set and maybe the old content
* SORT result is empty a new key is set and maybe the old content
* replaced. */
* replaced. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment