summaryrefslogtreecommitdiff
path: root/include/m_json.h
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-08-05 22:23:17 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-08-05 22:23:17 +0000
commit300b0d6897c31b9250dd6a60746646b036986983 (patch)
tree71066e1595776ed0e53efb0d1a91bd1b2c639d20 /include/m_json.h
parentedae1aa833a1223ca2e0b14d454fa114b3f0213b (diff)
fix for massive memory leak in json parser
git-svn-id: http://svn.miranda-ng.org/main/trunk@5593 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'include/m_json.h')
-rw-r--r--include/m_json.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/include/m_json.h b/include/m_json.h
index 8c4b25c6aa..3d82fe276b 100644
--- a/include/m_json.h
+++ b/include/m_json.h
@@ -69,7 +69,7 @@ MIR_CORE_DLL(void) json_set_n(JSONNODE * node, const JSONNODE * orig);
MIR_CORE_DLL(char) json_type(const JSONNODE * node);
MIR_CORE_DLL(size_t) json_size(const JSONNODE * node);
MIR_CORE_DLL(int) json_empty(const JSONNODE * node);
-MIR_CORE_DLL(char*) json_name(const JSONNODE * node);
+MIR_CORE_DLL(const char*) json_name(const JSONNODE * node);
#ifdef JSON_COMMENTS
MIR_CORE_DLL(char * json_get_comment(const JSONNODE * node);
#endif
@@ -117,6 +117,22 @@ MIR_CORE_DLL(int) json_equal(JSONNODE * node, JSONNODE * node2);
#ifdef __cplusplus
}
+
+class json_ptr
+{
+ char *data;
+
+public:
+ __inline json_ptr() : data(NULL) {}
+ __inline json_ptr(char *_p) : data(_p) {}
+ __inline ~json_ptr() { json_free(data); }
+ __inline char* operator = (char* _p) { if (data) json_free(data); data = _p; return data; }
+ __inline char* operator->() const { return data; }
+ __inline operator char*() const { return data; }
+};
+
+#define JSON_AS_STRING(A) ((char*)json_ptr(json_as_string(A)))
+
#endif
#endif // MIM_LIBJSON_H