summaryrefslogtreecommitdiffstats
path: root/xrescheck.c
diff options
context:
space:
mode:
authorRichard Grenville <pyxlcy@gmail.com>2014-08-03 19:40:40 +0800
committerRichard Grenville <pyxlcy@gmail.com>2014-08-03 19:40:40 +0800
commitebab3dc5061e58da34eed227e8f98965bdd1bc30 (patch)
tree61e81f85f8af76d7a982d183660200e2e036e6c2 /xrescheck.c
parent66b420aa62d28af6f6e7b064f58db446829b4f6a (diff)
downloadtdebase-ebab3dc5061e58da34eed227e8f98965bdd1bc30.tar.gz
tdebase-ebab3dc5061e58da34eed227e8f98965bdd1bc30.zip
Bug fix: Fix X pixmap leakage in shadow_paint
- Fix X pixmap leakage in shadow_paint. - Add the skeleton of a X resource leakage checker.
Diffstat (limited to 'xrescheck.c')
-rw-r--r--xrescheck.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/xrescheck.c b/xrescheck.c
new file mode 100644
index 000000000..6a63bed36
--- /dev/null
+++ b/xrescheck.c
@@ -0,0 +1,65 @@
+#include "xrescheck.h"
+
+static xrc_xid_record_t *gs_xid_records = NULL;
+
+#define HASH_ADD_XID(head, xidfield, add) \
+ HASH_ADD(hh, head, xidfield, sizeof(xid), add)
+
+#define HASH_FIND_XID(head, findxid, out) \
+ HASH_FIND(hh, head, findxid, sizeof(xid), out)
+
+#define M_CPY_POS_DATA(prec) \
+ prec->file = file; \
+ prec->func = func; \
+ prec->line = line; \
+
+/**
+ * @brief Add a record of given XID to the allocation table.
+ */
+void
+xrc_add_xid_(XID xid, const char *type, M_POS_DATA_PARAMS) {
+ xrc_xid_record_t *prec = cmalloc(1, xrc_xid_record_t);
+ prec->xid = xid;
+ prec->type = type;
+ M_CPY_POS_DATA(prec);
+
+ HASH_ADD_XID(gs_xid_records, xid, prec);
+}
+
+/**
+ * @brief Delete a record of given XID in the allocation table.
+ */
+void
+xrc_delete_xid_(XID xid, M_POS_DATA_PARAMS) {
+ xrc_xid_record_t *prec = NULL;
+ HASH_FIND_XID(gs_xid_records, &xid, prec);
+ if (!prec) {
+ printf_err("XRC: %s:%d %s(): Can't find XID %#010lx we want to delete.",
+ file, line, func, xid);
+ return;
+ }
+ HASH_DEL(gs_xid_records, prec);
+ free(prec);
+}
+
+/**
+ * @brief Report about issues found in the XID allocation table.
+ */
+void
+xrc_report_xid(void) {
+ for (xrc_xid_record_t *prec = gs_xid_records; prec; prec = prec->hh.next)
+ printf_dbg("XRC: %s:%d %s(): %#010lx (%s) not freed.\n",
+ prec->file, prec->line, prec->func, prec->xid, prec->type);
+}
+
+/**
+ * @brief Clear the XID allocation table.
+ */
+void
+xrc_clear_xid(void) {
+ xrc_xid_record_t *prec = NULL, *ptmp = NULL;
+ HASH_ITER(hh, gs_xid_records, prec, ptmp) {
+ HASH_DEL(gs_xid_records, prec);
+ free(prec);
+ }
+}