summaryrefslogtreecommitdiffstats
path: root/obj-types.h
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-30 08:02:42 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-30 08:02:42 +0000
commit4984c1ba6c84a3ae91f9afd4da2ea718c98c97a7 (patch)
tree39972db40d9d0f642879a663aadcad996a510e50 /obj-types.h
parentef44f5c9ba319e2813e5ea23b2699b73b63cdcbb (diff)
downloadrsyslog-4984c1ba6c84a3ae91f9afd4da2ea718c98c97a7.tar.gz
rsyslog-4984c1ba6c84a3ae91f9afd4da2ea718c98c97a7.tar.xz
rsyslog-4984c1ba6c84a3ae91f9afd4da2ea718c98c97a7.zip
- renamed Msg object to usual all-lowercase object name (else we ran into
troubles with the framework, also it was somewhat ugly...) - fixed a memory leak in object destruction (was recently introduced by object naming, not present in any released version)
Diffstat (limited to 'obj-types.h')
-rw-r--r--obj-types.h52
1 files changed, 49 insertions, 3 deletions
diff --git a/obj-types.h b/obj-types.h
index 030099bb..66dc4143 100644
--- a/obj-types.h
+++ b/obj-types.h
@@ -57,7 +57,7 @@ typedef struct {
/* object Types/IDs */
typedef enum { /* IDs of known object "types/classes" */
OBJNull = 0, /* no valid object (we do not start at zero so we can detect calloc()) */
- OBJMsg = 1,
+ OBJmsg = 1,
OBJstrm = 2,
OBJwtp = 3,
OBJwti = 4,
@@ -168,6 +168,7 @@ finalize_it: \
RETiRet; \
}
+
/* this defines both the constructor and initializer
* rgerhards, 2008-01-10
*/
@@ -185,7 +186,7 @@ finalize_it: \
DEFiRet; \
obj##_t *pThis; \
\
- assert(ppThis != NULL); \
+ ASSERT(ppThis != NULL); \
\
if((pThis = (obj##_t *)calloc(1, sizeof(obj##_t))) == NULL) { \
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY); \
@@ -193,12 +194,57 @@ finalize_it: \
objConstructSetObjInfo(pThis); \
\
obj##Initialize(pThis); \
- \
+ \
finalize_it: \
OBJCONSTRUCT_CHECK_SUCCESS_AND_CLEANUP \
RETiRet; \
}
+/* this defines the destructor. The important point is that the base object
+ * destructor is called. The upper-level class shall destruct all of its
+ * properties, but not the instance itself. This is freed here by the
+ * framework (we need an intact pointer because we need to free the
+ * obj_t structures inside it). A pointer to the object pointer must be
+ * parse, because it is re-set to NULL (this, for example, is important in
+ * cancellation handlers). The object pointer is always named pThis.
+ * The object is always freed, even if there is some error while
+ * Cancellation is blocked during destructors, as this could have fatal
+ * side-effects. However, this also means the upper-level object should
+ * not perform any lenghty processing.
+ * IMPORTANT: if the upper level object requires some situations where the
+ * object shall not be destructed (e.g. via reference counting), then
+ * it shall set pThis to NULL, which prevents destruction of the
+ * object.
+ * processing.
+ * rgerhards, 2008-01-30
+ */
+#define BEGINobjDestruct(obj) \
+ rsRetVal obj##Destruct(obj##_t **ppThis) \
+ { \
+ DEFiRet; \
+ int iCancelStateSave; \
+ obj##_t *pThis;
+
+#define CODESTARTobjDestruct(obj) \
+ ASSERT(ppThis != NULL); \
+ pThis = *ppThis; \
+ ISOBJ_TYPE_assert(pThis, obj); \
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &iCancelStateSave);
+
+#define ENDobjDestruct(obj) \
+ goto finalize_it; /* prevent compiler warning ;) */ \
+ /* no more code here! */ \
+ finalize_it: \
+ if(pThis != NULL) { \
+ objDestructObjSelf((obj_t*) pThis); \
+ free(pThis); \
+ *ppThis = NULL; \
+ } \
+ pthread_setcancelstate(iCancelStateSave, NULL); \
+ RETiRet; \
+ }
+
+
#endif /* #ifndef OBJ_TYPES_H_INCLUDED */