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
a37cca36
Commit
a37cca36
authored
Dec 11, 2019
by
Oran Agra
Browse files
fix leak in RM_LoadDataTypeFromString, and save
parent
7e24e219
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
a37cca36
...
@@ -3963,6 +3963,7 @@ void RM_DigestEndSequence(RedisModuleDigest *md) {
...
@@ -3963,6 +3963,7 @@ void RM_DigestEndSequence(RedisModuleDigest *md) {
void
*
RM_LoadDataTypeFromString
(
const
RedisModuleString
*
str
,
const
moduleType
*
mt
)
{
void
*
RM_LoadDataTypeFromString
(
const
RedisModuleString
*
str
,
const
moduleType
*
mt
)
{
rio
payload
;
rio
payload
;
RedisModuleIO
io
;
RedisModuleIO
io
;
void
*
ret
;
rioInitWithBuffer
(
&
payload
,
str
->
ptr
);
rioInitWithBuffer
(
&
payload
,
str
->
ptr
);
moduleInitIOContext
(
io
,(
moduleType
*
)
mt
,
&
payload
,
NULL
);
moduleInitIOContext
(
io
,(
moduleType
*
)
mt
,
&
payload
,
NULL
);
...
@@ -3971,7 +3972,12 @@ void *RM_LoadDataTypeFromString(const RedisModuleString *str, const moduleType *
...
@@ -3971,7 +3972,12 @@ void *RM_LoadDataTypeFromString(const RedisModuleString *str, const moduleType *
* need to make sure we read the same.
* need to make sure we read the same.
*/
*/
io
.
ver
=
2
;
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
/* 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
...
@@ -3989,11 +3995,15 @@ RedisModuleString *RM_SaveDataTypeToString(RedisModuleCtx *ctx, void *data, cons
rioInitWithBuffer
(
&
payload
,
sdsempty
());
rioInitWithBuffer
(
&
payload
,
sdsempty
());
moduleInitIOContext
(
io
,(
moduleType
*
)
mt
,
&
payload
,
NULL
);
moduleInitIOContext
(
io
,(
moduleType
*
)
mt
,
&
payload
,
NULL
);
mt
->
rdb_save
(
&
io
,
data
);
mt
->
rdb_save
(
&
io
,
data
);
if
(
io
.
ctx
)
{
moduleFreeContext
(
io
.
ctx
);
zfree
(
io
.
ctx
);
}
if
(
io
.
error
)
{
if
(
io
.
error
)
{
return
NULL
;
return
NULL
;
}
else
{
}
else
{
robj
*
str
=
createObject
(
OBJ_STRING
,
payload
.
io
.
buffer
.
ptr
);
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
;
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