mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-29 20:54:13 +01:00
Reclaim memory used for telldir cookies on closedir.
This commit is contained in:
parent
10b39986db
commit
b5c6599aa4
@ -55,5 +55,6 @@ closedir(dirp)
|
||||
dirp->dd_loc = 0;
|
||||
(void)free((void *)dirp->dd_buf);
|
||||
(void)free((void *)dirp);
|
||||
_reclaim_telldir(dirp);
|
||||
return(close(fd));
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ struct ddloc {
|
||||
long loc_index; /* key associated with structure */
|
||||
long loc_seek; /* magic cookie returned by getdirentries */
|
||||
long loc_loc; /* offset of entry in buffer */
|
||||
DIR* loc_dirp; /* directory which used this entry */
|
||||
};
|
||||
|
||||
#define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */
|
||||
@ -82,6 +83,7 @@ telldir(dirp)
|
||||
lp->loc_index = index;
|
||||
lp->loc_seek = dirp->dd_seek;
|
||||
lp->loc_loc = dirp->dd_loc;
|
||||
lp->loc_dirp = dirp;
|
||||
lp->loc_next = dd_hash[LOCHASH(index)];
|
||||
dd_hash[LOCHASH(index)] = lp;
|
||||
return (index);
|
||||
@ -126,3 +128,30 @@ found:
|
||||
free((caddr_t)lp);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Reclaim memory for telldir cookies which weren't used.
|
||||
*/
|
||||
void
|
||||
_reclaim_telldir(dirp)
|
||||
register DIR *dirp;
|
||||
{
|
||||
register struct ddloc *lp;
|
||||
register struct ddloc **prevlp;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NDIRHASH; i++) {
|
||||
prevlp = &dd_hash[i];
|
||||
lp = *prevlp;
|
||||
while (lp != NULL) {
|
||||
if (lp->loc_dirp == dirp) {
|
||||
*prevlp = lp->loc_next;
|
||||
free((caddr_t)lp);
|
||||
lp = *prevlp;
|
||||
continue;
|
||||
}
|
||||
prevlp = &lp->loc_next;
|
||||
lp = lp->loc_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user