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
c6fb9d09
Unverified
Commit
c6fb9d09
authored
Dec 11, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
Dec 11, 2019
Browse files
Merge pull request #6656 from oranagra/leak_rm_load_from_str
fix leak in RM_LoadDataTypeFromString, and save
parents
25b36f8d
a37cca36
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
c6fb9d09
...
...
@@ -3963,6 +3963,7 @@ void RM_DigestEndSequence(RedisModuleDigest *md) {
void
*
RM_LoadDataTypeFromString
(
const
RedisModuleString
*
str
,
const
moduleType
*
mt
)
{
rio
payload
;
RedisModuleIO
io
;
void
*
ret
;
rioInitWithBuffer
(
&
payload
,
str
->
ptr
);
moduleInitIOContext
(
io
,(
moduleType
*
)
mt
,
&
payload
,
NULL
);
...
...
@@ -3971,7 +3972,12 @@ void *RM_LoadDataTypeFromString(const RedisModuleString *str, const moduleType *
* need to make sure we read the same.
*/
io
.
ver
=
2
;
return
mt
->
rdb_load
(
&
io
,
0
);
ret
=
mt
->
rdb_load
(
&
io
,
0
);
if
(
io
.
ctx
)
{
moduleFreeContext
(
io
.
ctx
);
zfree
(
io
.
ctx
);
}
return
ret
;
}
/* Encode a module data type 'mt' value 'data' into serialized form, and return it
...
...
@@ -3989,11 +3995,15 @@ RedisModuleString *RM_SaveDataTypeToString(RedisModuleCtx *ctx, void *data, cons
rioInitWithBuffer
(
&
payload
,
sdsempty
());
moduleInitIOContext
(
io
,(
moduleType
*
)
mt
,
&
payload
,
NULL
);
mt
->
rdb_save
(
&
io
,
data
);
if
(
io
.
ctx
)
{
moduleFreeContext
(
io
.
ctx
);
zfree
(
io
.
ctx
);
}
if
(
io
.
error
)
{
return
NULL
;
}
else
{
robj
*
str
=
createObject
(
OBJ_STRING
,
payload
.
io
.
buffer
.
ptr
);
autoMemoryAdd
(
ctx
,
REDISMODULE_AM_STRING
,
str
);
if
(
ctx
!=
NULL
)
autoMemoryAdd
(
ctx
,
REDISMODULE_AM_STRING
,
str
);
return
str
;
}
}
...
...
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