-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I noticed a small memoty leak in usertools.c - we never free the "pcre
*re" member of sss_names_ctx, the attached patch fixes this with a
destructor of sss_names_ctx.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkrxfZwACgkQHsardTLnvCWNhgCfd96Hv3VNz/nW86sdhctHvDwq
lzoAn063OsTGfxf3F0v6Tk2cqNa/PzFo
=gM0q
-----END PGP SIGNATURE-----
>From 71faab6d2317ead67a5241f8365cfa70c42a9496 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <[email protected]>
Date: Tue, 3 Nov 2009 18:24:37 +0100
Subject: [PATCH] Free the PCRE regexp with destructor

---
 server/util/usertools.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/server/util/usertools.c b/server/util/usertools.c
index a3f7ad9..738ac62 100644
--- a/server/util/usertools.c
+++ b/server/util/usertools.c
@@ -45,6 +45,15 @@ char *get_username_from_uid(TALLOC_CTX *mem_ctx, uid_t uid)
     return username;
 }
 
+static int sss_names_ctx_destructor(struct sss_names_ctx *snctx)
+{
+    if (snctx->re) {
+        pcre_free(snctx->re);
+        snctx->re = NULL;
+    }
+    return 0;
+}
+
 int sss_names_init(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb, struct sss_names_ctx **out)
 {
     struct sss_names_ctx *ctx;
@@ -55,6 +64,7 @@ int sss_names_init(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb, struct sss_names
 
     ctx = talloc_zero(mem_ctx, struct sss_names_ctx);
     if (!ctx) return ENOMEM;
+    talloc_set_destructor(ctx, sss_names_ctx_destructor);
 
     ret = confdb_get_string(cdb, ctx, CONFDB_MONITOR_CONF_ENTRY,
                             CONFDB_MONITOR_NAME_REGEX, NULL, &ctx->re_pattern);
-- 
1.6.2.5

_______________________________________________
sssd-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to