diff options
author | Colin Watson <cjwatson@debian.org> | 2022-09-24 14:46:47 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2022-09-24 14:46:48 +0100 |
commit | b1615c44fe20c205be2b5ba5cd95e0cc8510d766 (patch) | |
tree | 4b654b3ddea1c6e4da999597e4fc40138fd3876e /libdb | |
parent | 26b957306113c1cf47133268a938f32c31722ab3 (diff) |
Simplify struct mandata memory allocation
The arrangement where most of the fields of `struct mandata` were
constant pointers into the `addr` field was a bit more memory-efficient,
but it made some kinds of analysis and reorganization very difficult,
and we don't actually need to be quite that frugal about memory.
Reorganize this to allocate each field independently instead.
* lib/filenames.c (filename_info): Allocate each field independently.
Use Gnulib's `base_name` and `dir_name` functions to parse paths. Stop
setting `info->addr`.
(free_mandata_struct): Free the `ext`, `sec`, `pointer`, `comp`,
`filter`, and `whatis` fields. Stop freeing `addr`.
* lib/filenames.h (struct mandata): Remove `addr`. Make `ext`, `sec`,
`pointer`, `comp`, `filter`, and `whatis` non-`const`.
* libdb/db_lookup.c (split_content): Copy the `ext`, `sec`, `pointer`,
`filter`, `comp`, and `whatis` fields. Stop setting `addr`.
* libdb/db_store.c (make_content): Copy the `pointer`, `comp`, `filter`,
and `whatis` fields.
* src/descriptions_store.c (store_descriptions): Copy `pointer` and
`whatis` fields.
* src/straycats.c (check_for_stray): Copy `comp`, `ext`, `sec`, and
`filter` fields.
* libdb/db_lookup.c (dblookup): Always free `cont`'s data pointer, since
it's no longer sometimes borrowed.
* libdb/db_store.c (dbstore): Free `cont`'s and `oldcont`'s data
pointers, since they're no longer borrowed.
* src/check_mandirs.c (purge_missing): Free `content`'s data pointer,
since it's no longer borrowed.
* libdb/db_lookup.c (dblookup_pattern): Stop freeing `info->addr`.
* src/catman.c (parse_for_sec): Stop freeing `entry->addr`.
* src/whatis.c (do_apropos): Stop freeing `info->addr`.
Diffstat (limited to 'libdb')
-rw-r--r-- | libdb/db_lookup.c | 18 | ||||
-rw-r--r-- | libdb/db_store.c | 16 |
2 files changed, 15 insertions, 19 deletions
diff --git a/libdb/db_lookup.c b/libdb/db_lookup.c index 2cacdb73..b43269a6 100644 --- a/libdb/db_lookup.c +++ b/libdb/db_lookup.c @@ -199,17 +199,15 @@ struct mandata *split_content (MYDBM_FILE dbf, char *cont_ptr) info = XZALLOC (struct mandata); info->name = copy_if_set (*(data++)); - info->ext = *(data++); - info->sec = *(data++); + info->ext = xstrdup (*(data++)); + info->sec = xstrdup (*(data++)); info->mtime.tv_sec = (time_t) atol (*(data++)); info->mtime.tv_nsec = atol (*(data++)); info->id = **(data++); /* single char id */ - info->pointer = *(data++); - info->filter = *(data++); - info->comp = *(data++); - info->whatis = *(data); - - info->addr = cont_ptr; + info->pointer = xstrdup (*(data++)); + info->filter = xstrdup (*(data++)); + info->comp = xstrdup (*(data++)); + info->whatis = xstrdup (*(data)); return info; } @@ -368,8 +366,8 @@ static gl_list_t dblookup (MYDBM_FILE dbf, const char *page, } gl_list_free (refs); - MYDBM_FREE_DPTR (cont); } + MYDBM_FREE_DPTR (cont); return infos; } @@ -505,8 +503,6 @@ nextpage: MYDBM_FREE_DPTR (key); end = man_btree_nextkeydata (dbf, &key, &cont); #endif /* !BTREE */ - if (info) - info->addr = NULL; free_mandata_struct (info); } diff --git a/libdb/db_store.c b/libdb/db_store.c index 92926dc7..eae5c271 100644 --- a/libdb/db_store.c +++ b/libdb/db_store.c @@ -135,13 +135,13 @@ static datum make_content (struct mandata *in) memset (&cont, 0, sizeof cont); if (!in->pointer) - in->pointer = dash; - if (!in->filter) - in->filter = dash; + in->pointer = xstrdup (dash); if (!in->comp) - in->comp = dash; + in->comp = xstrdup (dash); + if (!in->filter) + in->filter = xstrdup (dash); if (!in->whatis) - in->whatis = dash + 1; + in->whatis = xstrdup (dash + 1); value = xasprintf ( "%s\t%s\t%s\t%ld\t%ld\t%c\t%s\t%s\t%s\t%s", @@ -278,7 +278,7 @@ int dbstore (MYDBM_FILE dbf, struct mandata *in, const char *base) info = split_content (dbf, MYDBM_DPTR (cont)); ret = replace_if_necessary (dbf, in, info, newkey, newcont); - /* MYDBM_FREE_DPTR (cont); */ + MYDBM_FREE_DPTR (cont); free_mandata_struct (info); MYDBM_FREE_DPTR (newkey); MYDBM_FREE_DPTR (newcont); @@ -348,7 +348,7 @@ int dbstore (MYDBM_FILE dbf, struct mandata *in, const char *base) newcont = make_content (in); ret = replace_if_necessary (dbf, in, old, oldkey, newcont); - /* MYDBM_FREE_DPTR (oldcont); */ + MYDBM_FREE_DPTR (oldcont); free_mandata_struct (old); MYDBM_FREE_DPTR (newcont); MYDBM_FREE_DPTR (lastkey); @@ -412,7 +412,7 @@ int dbstore (MYDBM_FILE dbf, struct mandata *in, const char *base) if (MYDBM_REPLACE (dbf, oldkey, newcont)) gripe_replace_key (dbf, MYDBM_DPTR (oldkey)); - /* MYDBM_FREE_DPTR (oldcont); */ + MYDBM_FREE_DPTR (oldcont); free_mandata_struct (old); MYDBM_FREE_DPTR (newcont); free (old_name); |