diff options
author | Colin Watson <cjwatson@debian.org> | 2022-09-24 13:44:03 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2022-09-24 13:44:03 +0100 |
commit | 4a213af168ca05021aa8cd137194b06144ca604a (patch) | |
tree | a693af4dc987b9b59bd5b22d26dbf33aeda3b75f /src | |
parent | 40cd7c5a3e05e6d830f1cf39fe6532804b51dae2 (diff) |
Always allocate struct mandata on the heap
This means we no longer need two slightly different functions for
freeing it.
* libdb/db_lookup.c (dblookup_pattern): Allocate `struct mandata` on the
heap. Simplify arrangements for adding to the `infos` list.
(dbstore): Allocate `struct mandata` on the heap.
* src/catman.c (parse_for_sec): Likewise.
* src/check_mandirs.c (purge_pointers, purge_missing): Likewise.
* src/straycats.c (check_for_stray): Likewise.
* src/whatis.c (do_apropos): Likewise.
* lib/filenames.c (free_mandata_elements): Remove function and move its
contents to ...
(free_mandata_struct): ... here, if `pinfo` is set.
* lib/filenames.h (free_mandata_elements): Remove prototype.
Diffstat (limited to 'src')
-rw-r--r-- | src/catman.c | 13 | ||||
-rw-r--r-- | src/check_mandirs.c | 49 | ||||
-rw-r--r-- | src/straycats.c | 39 | ||||
-rw-r--r-- | src/whatis.c | 21 |
4 files changed, 63 insertions, 59 deletions
diff --git a/src/catman.c b/src/catman.c index 2da9d03d..92ec3ad0 100644 --- a/src/catman.c +++ b/src/catman.c @@ -283,16 +283,17 @@ static int parse_for_sec (MYDBM_FILE dbf, #endif if (*MYDBM_DPTR (content) != '\t') { #pragma GCC diagnostic pop - struct mandata entry; + struct mandata *entry; + entry = XZALLOC (struct mandata); split_content (dbf, MYDBM_DPTR (content), - &entry); + entry); /* Accept if the entry is an ultimate manual page and the section matches the one we're currently dealing with */ - if (entry.id == ULT_MAN && - strcmp (entry.sec, section) == 0) { + if (entry->id == ULT_MAN && + strcmp (entry->sec, section) == 0) { if (message) { printf (_("\nUpdating cat files for section %s of man hierarchy %s\n"), section, manpath); @@ -319,8 +320,8 @@ static int parse_for_sec (MYDBM_FILE dbf, } /* == MYDBM_DPTR (content), freed below */ - entry.addr = NULL; - free_mandata_elements (&entry); + entry->addr = NULL; + free_mandata_struct (entry); } /* we don't need the content ever again */ diff --git a/src/check_mandirs.c b/src/check_mandirs.c index 419efb5d..13d3fb57 100644 --- a/src/check_mandirs.c +++ b/src/check_mandirs.c @@ -706,7 +706,7 @@ void purge_pointers (MYDBM_FILE dbf, const char *name) while (MYDBM_DPTR (key) != NULL) { datum content, nextkey; - struct mandata entry; + struct mandata *entry = NULL; char *nicekey, *tab; #pragma GCC diagnostic push @@ -736,19 +736,21 @@ void purge_pointers (MYDBM_FILE dbf, const char *name) goto pointers_contentnext; #pragma GCC diagnostic pop - split_content (dbf, MYDBM_DPTR (content), &entry); - if (entry.id != SO_MAN && entry.id != WHATIS_MAN) + entry = XZALLOC (struct mandata); + split_content (dbf, MYDBM_DPTR (content), entry); + if (entry->id != SO_MAN && entry->id != WHATIS_MAN) goto pointers_contentnext; - if (STREQ (entry.pointer, name)) { + if (STREQ (entry->pointer, name)) { if (!opt_test) - dbdelete (dbf, nicekey, &entry); + dbdelete (dbf, nicekey, entry); else debug ("%s(%s): pointer vanished, " - "would delete\n", nicekey, entry.ext); + "would delete\n", nicekey, entry->ext); } pointers_contentnext: + free_mandata_struct (entry); free (nicekey); MYDBM_FREE_DPTR (content); pointers_next: @@ -965,7 +967,7 @@ int purge_missing (MYDBM_FILE dbf, const char *manpath, const char *catpath) while (MYDBM_DPTR (key) != NULL) { datum content, nextkey; - struct mandata entry; + struct mandata *entry; char *nicekey, *tab; bool save_debug; gl_list_t found; @@ -1014,39 +1016,40 @@ int purge_missing (MYDBM_FILE dbf, const char *manpath, const char *catpath) } #pragma GCC diagnostic pop - split_content (dbf, MYDBM_DPTR (content), &entry); + entry = XZALLOC (struct mandata); + split_content (dbf, MYDBM_DPTR (content), entry); save_debug = debug_level; debug_level = false; /* look_for_file() is quite noisy */ - if (entry.id <= WHATIS_MAN) - found = look_for_file (manpath, entry.ext, - entry.name ? entry.name - : nicekey, + if (entry->id <= WHATIS_MAN) + found = look_for_file (manpath, entry->ext, + entry->name ? entry->name + : nicekey, 0, LFF_MATCHCASE); else - found = look_for_file (catpath, entry.ext, - entry.name ? entry.name - : nicekey, + found = look_for_file (catpath, entry->ext, + entry->name ? entry->name + : nicekey, 1, LFF_MATCHCASE); debug_level = save_debug; /* Now actually decide whether to purge, depending on the * type of entry. */ - if (entry.id == ULT_MAN || entry.id == SO_MAN || - entry.id == STRAY_CAT) - count += purge_normal (dbf, nicekey, &entry, found); - else if (entry.id == WHATIS_MAN) + if (entry->id == ULT_MAN || entry->id == SO_MAN || + entry->id == STRAY_CAT) + count += purge_normal (dbf, nicekey, entry, found); + else if (entry->id == WHATIS_MAN) count += purge_whatis (dbf, manpath, 0, nicekey, - &entry, found, db_mtime); - else /* entry.id == WHATIS_CAT */ + entry, found, db_mtime); + else /* entry->id == WHATIS_CAT */ count += purge_whatis (dbf, catpath, 1, nicekey, - &entry, found, db_mtime); + entry, found, db_mtime); gl_list_free (found); free (nicekey); - free_mandata_elements (&entry); + free_mandata_struct (entry); nextkey = MYDBM_NEXTKEY (dbf, key); MYDBM_FREE_DPTR (key); key = nextkey; diff --git a/src/straycats.c b/src/straycats.c index 3b2b6d4c..e0bf871b 100644 --- a/src/straycats.c +++ b/src/straycats.c @@ -112,13 +112,13 @@ static int check_for_stray (MYDBM_FILE dbf) lencat = strlen (catdir); GL_LIST_FOREACH (names, name) { - struct mandata info; - char *ext, *section; + struct mandata *info; + char *ext, *section = NULL; short found; struct stat buf; struct compression *comp; - memset (&info, 0, sizeof (struct mandata)); + info = XZALLOC (struct mandata); *(mandir + lenman) = *(catdir + lencat) = '\0'; mandir = appendstr (mandir, name, (void *) 0); @@ -131,12 +131,12 @@ static int check_for_stray (MYDBM_FILE dbf) _("warning: %s: " "ignoring bogus filename"), catdir); - continue; + goto next; } else if (comp_info (ext, 0)) { *ext = '\0'; - info.comp = ext + 1; + info->comp = ext + 1; } else - info.comp = NULL; + info->comp = NULL; ext = strrchr (mandir, '.'); *(mandir + lenman - 1) = '\0'; @@ -151,7 +151,7 @@ static int check_for_stray (MYDBM_FILE dbf) _("warning: %s: " "ignoring bogus filename"), catdir); - goto next_section; + goto next; } /* @@ -184,27 +184,25 @@ static int check_for_stray (MYDBM_FILE dbf) lg.whatis = 0; *(ext++) = '\0'; - info.ext = ext; + info->ext = ext; /* see if we already have it, before going any further */ mandir_base = base_name (mandir); - exists = dblookup_exact (dbf, mandir_base, info.ext, + exists = dblookup_exact (dbf, mandir_base, info->ext, true); if (exists && compare_ids (STRAY_CAT, exists->id, 0) >= 0) goto next_exists; debug ("%s(%s) is not in the db.\n", - mandir_base, info.ext); + mandir_base, info->ext); /* fill in the missing parts of the structure */ - info.name = NULL; - info.sec = section; - info.id = STRAY_CAT; - info.pointer = NULL; - info.filter = "-"; - info.mtime.tv_sec = 0; - info.mtime.tv_nsec = 0; + info->sec = section; + info->id = STRAY_CAT; + info->filter = "-"; + info->mtime.tv_sec = 0; + info->mtime.tv_nsec = 0; drop_effective_privs (); decomp = decompress_open (catdir, 0); @@ -265,13 +263,13 @@ static int check_for_stray (MYDBM_FILE dbf) strays++; descs = parse_descriptions (mandir_base, lg.whatis); - store_descriptions (dbf, descs, &info, + store_descriptions (dbf, descs, info, NULL, mandir_base, NULL); gl_list_free (descs); } else if (quiet < 2) error (0, 0, _("warning: %s: whatis parse for %s(%s) failed"), - catdir, mandir_base, info.sec); + catdir, mandir_base, info->sec); free (catdir_base); } @@ -281,8 +279,9 @@ next_exists: free_mandata_struct (exists); free (mandir_base); } -next_section: +next: free (section); + free_mandata_struct (info); } gl_list_free (names); return strays; diff --git a/src/whatis.c b/src/whatis.c index 2f393fa8..bc3f3bb6 100644 --- a/src/whatis.c +++ b/src/whatis.c @@ -690,9 +690,7 @@ static void do_apropos (MYDBM_FILE dbf, while (!end) { #endif /* !BTREE */ char *tab; - struct mandata info; - - memset (&info, 0, sizeof (info)); + struct mandata *info = NULL; /* bug#4372, NULL pointer dereference in MYDBM_DPTR (cont), * fix by dassen@wi.leidenuniv.nl (J.H.M.Dassen), thanx Ray. @@ -721,7 +719,8 @@ static void do_apropos (MYDBM_FILE dbf, /* a real page */ - split_content (dbf, MYDBM_DPTR (cont), &info); + info = XZALLOC (struct mandata); + split_content (dbf, MYDBM_DPTR (cont), info); /* If there are sections given, does any of them match * either the section or extension of this page? @@ -731,8 +730,8 @@ static void do_apropos (MYDBM_FILE dbf, int matched = 0; for (section = sections; *section; ++section) { - if (STREQ (*section, info.sec) || - STREQ (*section, info.ext)) { + if (STREQ (*section, info->sec) || + STREQ (*section, info->ext)) { matched = 1; break; } @@ -752,14 +751,14 @@ static void do_apropos (MYDBM_FILE dbf, if (am_apropos) { char *whatis; - whatis = info.whatis ? xstrdup (info.whatis) : NULL; + whatis = info->whatis ? xstrdup (info->whatis) : NULL; if (!combine (num_pages, found_here) && whatis) parse_whatis (pages, num_pages, whatis, found, found_here); free (whatis); } if (combine (num_pages, found_here)) - display (dbf, &info, MYDBM_DPTR (key)); + display (dbf, info, MYDBM_DPTR (key)); if (tab) *tab = '\t'; @@ -779,8 +778,10 @@ nextpage: end = man_btree_nextkeydata (dbf, &key, &cont); #endif /* !BTREE */ #pragma GCC diagnostic pop - info.addr = NULL; /* == MYDBM_DPTR (cont), freed above */ - free_mandata_elements (&info); + if (info) + /* == MYDBM_DPTR (cont), freed above */ + info->addr = NULL; + free_mandata_struct (info); } free (found_here); |