-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leak on unset of associative array (#64)
Associative arrays weren't being properly freed from memory, which was causing a memory leak. This commit incorporates a patch and reproducer/regress test from: https://www.mail-archive.com/[email protected]/msg01016.html src/cmd/ksh93/sh/name.c: - Properly free associative arrays from memory in nv_delete(). src/cmd/ksh93/tests/leaks.sh: - Add regression test.
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,4 +101,25 @@ done | |
after=$(getmem) | ||
(( after > before )) && err_exit "memory leak with read -C when using <<< (leaked $((after - before)) $unit)" | ||
|
||
# ====== | ||
# Unsetting an associative array shouldn't cause a memory leak | ||
# See https://www.mail-archive.com/[email protected]/msg01016.html | ||
typeset -A stuff | ||
before=$(getmem) | ||
for (( i=0; i<1000; i++ )) | ||
do | ||
unset stuff[xyz] | ||
typeset -A stuff[xyz] | ||
stuff[xyz][elem0]="data0" | ||
stuff[xyz][elem1]="data1" | ||
stuff[xyz][elem2]="data2" | ||
stuff[xyz][elem3]="data3" | ||
stuff[xyz][elem4]="data4" | ||
done | ||
unset stuff | ||
after=$(getmem) | ||
(( after > before )) && err_exit 'unset of associative array causes memory leak' \ | ||
"(leaked $((after - before)) $unit)" | ||
|
||
# ====== | ||
exit $((Errors<125?Errors:125)) |