From b02bdba74968a2671650f7212d6c98fc17f91596 Mon Sep 17 00:00:00 2001 From: sobomax Date: Mon, 9 Sep 2002 08:00:32 +0000 Subject: Vastly decrease amount of memory comsumed in the case when we have to read ports/INDEX, by allocating eactly amount of memory necessary for storing each particular entry, insdead of 4K per entry (more than 7000 entries - go figure). Memory consumption went down to some 500K from some 30M. --- usr.sbin/pkg_install/version/perform.c | 11 +++++++++-- usr.sbin/pkg_install/version/version.h | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'usr.sbin/pkg_install') diff --git a/usr.sbin/pkg_install/version/perform.c b/usr.sbin/pkg_install/version/perform.c index efc4dff..fa71dfb 100644 --- a/usr.sbin/pkg_install/version/perform.c +++ b/usr.sbin/pkg_install/version/perform.c @@ -68,6 +68,8 @@ pkg_perform(char **indexarg) i = -1; while (pkgs[++i] != NULL) { if (MatchName == NULL || strstr(pkgs[i], MatchName)) + if (strcmp(pkgs[i], "mpeg_lib-1.3.1") == 0) + printf("Found!\n"); err_cnt += pkg_do(pkgs[i]); } @@ -75,6 +77,10 @@ pkg_perform(char **indexarg) while (!SLIST_EMPTY(&Index)) { ie = SLIST_FIRST(&Index); SLIST_REMOVE_HEAD(&Index, next); + if (ie->name != NULL) + free(ie->name); + if (ie->origin != NULL) + free(ie->origin); free(ie); } if (IndexFile != NULL) @@ -157,8 +163,9 @@ pkg_do(char *pkg) errx(2, "The INDEX does not appear to be valid!"); if ((ie = malloc(sizeof(struct index_entry))) == NULL) errx(2, "Unable to allocate memory in %s.", __func__); - strlcpy(ie->name, tmp, PATH_MAX); - strlcpy(ie->origin, &ch[1], PATH_MAX); + bzero(ie, sizeof(struct index_entry)); + ie->name = strdup(tmp); + ie->origin = strdup(&ch[1]); /* Who really cares if we reverse the index... */ SLIST_INSERT_HEAD(&Index, ie, next); } diff --git a/usr.sbin/pkg_install/version/version.h b/usr.sbin/pkg_install/version/version.h index 6ed6511..daaebb0 100644 --- a/usr.sbin/pkg_install/version/version.h +++ b/usr.sbin/pkg_install/version/version.h @@ -32,8 +32,8 @@ struct index_entry { SLIST_ENTRY(index_entry) next; - char name[PATH_MAX]; - char origin[PATH_MAX]; + char *name; + char *origin; }; SLIST_HEAD(index_head, index_entry); -- cgit v1.1