From ccc1c731529de16f6fa4064fd992a8f63d7cfc26 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 11 Jan 2008 00:01:58 -0600 Subject: Use dynamic string allocation in package structures This also affects all structures with static strings, such as depmiss, conflict, etc. This should help a lot with memory usage, and hopefully make things a bit more "idiot proof". Currently our pactest pass/fail rate is identical before and after this patch. This is not to say it is a perfect patch- I have yet to pull valgrind out. However, this should be quite safe to use in all situations from here on out, and we can start plugging the memleaks. Original-work-by: Aaron Griffin Signed-off-by: Dan McGee --- lib/libalpm/db.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/libalpm/db.c') diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index d8e770b8..54a31e95 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -500,18 +500,16 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles) for(j = _alpm_db_get_pkgcache(db); j; j = j->next) { pmpkg_t *pkg = j->data; const char *matched = NULL; + const char *name = alpm_pkg_get_name(pkg); + const char *desc = alpm_pkg_get_desc(pkg); - /* check name */ - if (regexec(®, alpm_pkg_get_name(pkg), 0, 0, 0) == 0) { - matched = alpm_pkg_get_name(pkg); - } - /* check plain text name */ - else if (strstr(alpm_pkg_get_name(pkg), targ)) { - matched = alpm_pkg_get_name(pkg); + /* check name as regex AND as plain text */ + if(name && (regexec(®, name, 0, 0, 0) == 0 || strstr(name, targ))) { + matched = name; } /* check desc */ - else if (regexec(®, alpm_pkg_get_desc(pkg), 0, 0, 0) == 0) { - matched = alpm_pkg_get_desc(pkg); + else if (desc && regexec(®, desc, 0, 0, 0) == 0) { + matched = desc; } /* check provides */ /* TODO: should we be doing this, and should we print something -- cgit v1.2.3-24-g4f1b