[augeas-devel] [PATCH] Fix segfault when aug_init/close are called multiple times
David Lutterkort
dlutter at redhat.com
Thu Jun 12 20:28:16 UTC 2008
1 file changed, 19 insertions(+), 17 deletions(-)
src/lens.c | 36 +++++++++++++++++++-----------------
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1213302482 25200
# Node ID 1f84686b8d3f7bc511445af8501cf957f066a3b5
# Parent c8ae86c46ac1081a42e6e23fa2a828ce607fe4f9
Fix segfault when aug_init/close are called multiple times
The way we cached the regexp '[0-9]+/' was totally botched. We now allocate
the pattern statically in memory and pin it to protect it from being freed,
ever.
diff -r c8ae86c46ac1 -r 1f84686b8d3f src/lens.c
--- a/src/lens.c Fri Jun 06 13:56:12 2008 -0700
+++ b/src/lens.c Thu Jun 12 13:28:02 2008 -0700
@@ -24,8 +24,6 @@
#include "lens.h"
#include "memory.h"
-
-static struct regexp *regexp_digits = NULL;
static struct value * typecheck_union(struct info *,
struct lens *l1, struct lens *l2);
@@ -442,6 +440,17 @@
return regexp;
}
+static struct regexp *make_regexp_from_string(struct info *info,
+ struct string *string) {
+ struct regexp *r;
+ make_ref(r);
+ if (r != NULL) {
+ r->info = ref(info);
+ r->pattern = ref(string);
+ }
+ return r;
+}
+
/* Calculate the regexp that matches the labels if the trees that L can
generate.
@@ -452,31 +461,24 @@
*/
static struct regexp *lns_key_regexp(struct lens *l, struct value **exn) {
static const struct string leaf_key_string = {
- .ref = UINT_MAX, .str = (char *) "/"
+ .ref = REF_MAX, .str = (char *) "/"
};
static const struct string *const leaf_key_pat = &leaf_key_string;
+
+ static const struct string digits_string = {
+ .ref = REF_MAX, .str = (char *) "[0-9]+/"
+ };
+ static const struct string *const digits_pat = &digits_string;
*exn = NULL;
switch(l->tag) {
case L_STORE:
- {
- struct regexp *r;
- make_ref(r);
- r->info = ref(l->info);
- r->pattern = (struct string *) leaf_key_pat;
- return r;
- }
+ return make_regexp_from_string(l->info, (struct string *) leaf_key_pat);
case L_DEL:
case L_COUNTER:
return NULL;
case L_SEQ:
- if (regexp_digits == NULL) {
- regexp_digits = make_regexp(l->info, strdup("[0-9]+/"));
- return regexp_digits;
- } else {
- return ref(regexp_digits);
- }
- break;
+ return make_regexp_from_string(l->info, (struct string *) digits_pat);
case L_KEY:
return make_key_regexp(l->info, l->regexp->pattern->str);
case L_LABEL:
More information about the augeas-devel
mailing list