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
2069d06a
Commit
2069d06a
authored
Mar 17, 2010
by
antirez
Browse files
Fixed a bug in HSET, a memory leak, and a theoretical bug in dict.c
parent
b1d9c91c
Changes
2
Hide whitespace changes
Inline
Side-by-side
dict.c
View file @
2069d06a
...
...
@@ -232,7 +232,7 @@ int dictAdd(dict *ht, void *key, void *val)
* operation. */
int
dictReplace
(
dict
*
ht
,
void
*
key
,
void
*
val
)
{
dictEntry
*
entry
;
dictEntry
*
entry
,
auxentry
;
/* Try to add the element. If the key
* does not exists dictAdd will suceed. */
...
...
@@ -241,8 +241,14 @@ int dictReplace(dict *ht, void *key, void *val)
/* It already exists, get the entry */
entry
=
dictFind
(
ht
,
key
);
/* Free the old value and set the new one */
dictFreeEntryVal
(
ht
,
entry
);
/* Set the new value and free the old one. Note that it is important
* to do that in this order, as the value may just be exactly the same
* as the previous one. In this context, think to reference counting,
* you want to increment (set), and then decrement (free), and not the
* reverse. */
auxentry
=
*
entry
;
dictSetHashVal
(
ht
,
entry
,
val
);
dictFreeEntryVal
(
ht
,
&
auxentry
);
return
0
;
}
...
...
redis.c
View file @
2069d06a
...
...
@@ -5849,7 +5849,7 @@ static void hsetCommand(redisClient *c) {
tryObjectEncoding
(
c
->
argv
[
2
]);
/* note that c->argv[3] is already encoded, as the latest arg
* of a bulk command is always integer encoded if possible. */
if
(
dict
Add
(
o
->
ptr
,
c
->
argv
[
2
],
c
->
argv
[
3
])
==
DICT_OK
)
{
if
(
dict
Replace
(
o
->
ptr
,
c
->
argv
[
2
],
c
->
argv
[
3
]))
{
incrRefCount
(
c
->
argv
[
2
]);
}
else
{
update
=
1
;
...
...
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