Skip to content

Commit

Permalink
Fix memory leak json parsing fails (#10)
Browse files Browse the repository at this point in the history
Wrap raw pointer into std::unique_ptr which would gracefully handle
deallocation when reader->parse finishes with error.

Co-authored-by: vperus <vperus@penguin>
  • Loading branch information
VPeruS and vperus committed May 14, 2020
1 parent 382fe68 commit cb008b3
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ std::vector<std::ostream*> g_logging_err_outs = {
#define IPC_JSON_READ(ROOT) \
{ \
Json::CharReaderBuilder b; \
Json::CharReader* reader(b.newCharReader()); \
const std::unique_ptr<Json::CharReader> reader(b.newCharReader()); \
JSONCPP_STRING error; \
if(!reader->parse(buf->payload, buf->payload + buf->header->size, &ROOT, &error)) { \
throw invalid_reply_payload_error(auss_t() << "Failed to parse reply on \"" i3IPC_TYPE_STR "\": " << error); \
} \
delete reader; \
}

#define IPC_JSON_ASSERT_TYPE(OBJ, OBJ_DESCR, TYPE_CHECK, TYPE_NAME) \
Expand Down

0 comments on commit cb008b3

Please sign in to comment.