Repository navigation
Commit 705912c
committed
ext4: teach ext4_ext_find_extent() to free path on error
Right now, there are a places where it is all to easy to leak memory
on an error path, via a usage like this:
struct ext4_ext_path *path = NULL
while (...) {
...
path = ext4_ext_find_extent(inode, block, path, 0);
if (IS_ERR(path)) {
/* oops, if path was non-NULL before the call to
ext4_ext_find_extent, we've leaked it! :-( */
...
return PTR_ERR(path);
}
...
}
Unfortunately, there some code paths where we are doing the following
instead:
path = ext4_ext_find_extent(inode, block, orig_path, 0);
and where it's important that we _not_ free orig_path in the case
where ext4_ext_find_extent() returns an error.
So change the function signature of ext4_ext_find_extent() so that it
takes a struct ext4_ext_path ** for its third argument, and by
default, on an error, it will free the struct ext4_ext_path, and then
zero out the struct ext4_ext_path * pointer. In order to avoid
causing problems, we add a flag EXT4_EX_NOFREE_ON_ERR which causes
ext4_ext_find_extent() to use the original behavior of forcing the
caller to deal with freeing the original path pointer on the error
case.
The goal is to get rid of EXT4_EX_NOFREE_ON_ERR entirely, but this
allows for a gentle transition and makes the patches easier to verify.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>1 parent bd30d70 commit 705912c
3 files changed
Lines changed: 21 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
| 585 | + | |
585 | 586 | | |
586 | 587 | | |
587 | 588 | | |
| |||
2733 | 2734 | | |
2734 | 2735 | | |
2735 | 2736 | | |
2736 | | - | |
| 2737 | + | |
2737 | 2738 | | |
2738 | 2739 | | |
2739 | 2740 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
855 | 855 | | |
856 | 856 | | |
857 | 857 | | |
858 | | - | |
| 858 | + | |
859 | 859 | | |
860 | 860 | | |
861 | 861 | | |
862 | | - | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
863 | 865 | | |
864 | 866 | | |
865 | 867 | | |
| |||
871 | 873 | | |
872 | 874 | | |
873 | 875 | | |
874 | | - | |
| 876 | + | |
875 | 877 | | |
876 | 878 | | |
877 | 879 | | |
| |||
923 | 925 | | |
924 | 926 | | |
925 | 927 | | |
926 | | - | |
| 928 | + | |
927 | 929 | | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
928 | 933 | | |
929 | 934 | | |
930 | 935 | | |
| |||
1356 | 1361 | | |
1357 | 1362 | | |
1358 | 1363 | | |
1359 | | - | |
| 1364 | + | |
1360 | 1365 | | |
1361 | 1366 | | |
1362 | 1367 | | |
| |||
1369 | 1374 | | |
1370 | 1375 | | |
1371 | 1376 | | |
1372 | | - | |
| 1377 | + | |
1373 | 1378 | | |
1374 | 1379 | | |
1375 | 1380 | | |
| |||
2152 | 2157 | | |
2153 | 2158 | | |
2154 | 2159 | | |
2155 | | - | |
| 2160 | + | |
2156 | 2161 | | |
2157 | 2162 | | |
2158 | 2163 | | |
| |||
3313 | 3318 | | |
3314 | 3319 | | |
3315 | 3320 | | |
3316 | | - | |
| 3321 | + | |
| 3322 | + | |
3317 | 3323 | | |
3318 | 3324 | | |
3319 | 3325 | | |
| |||
3697 | 3703 | | |
3698 | 3704 | | |
3699 | 3705 | | |
3700 | | - | |
| 3706 | + | |
| 3707 | + | |
3701 | 3708 | | |
3702 | 3709 | | |
3703 | 3710 | | |
| |||
3769 | 3776 | | |
3770 | 3777 | | |
3771 | 3778 | | |
3772 | | - | |
| 3779 | + | |
| 3780 | + | |
3773 | 3781 | | |
3774 | 3782 | | |
3775 | 3783 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
0 commit comments