Commit 440f57f
committed
tools/cgxget: free temporary conversions on failure paths
AddressSanitizer reported an 8-byte leak when convert_cgroups() aborted:
Direct leak of 8 byte(s) in 1 object(s) allocated from:
#0 0x... in __interceptor_malloc
#1 convert_cgroups (<libcgroup-source>/src/tools/cgxget.c:822)
libcgroup#2 main (<libcgroup-source>/src/tools/cgxget.c:893)
The helper allocates a scratch cgroup list, but on failures or
ECGNOVERSIONCONVERT it returned without releasing the partially built
array. Worse, when the scratch malloc failed we still treated the
conversion as “success” and left the old list pointing nowhere.
Return an error if the allocation fails, zero-initialise the scratch
list so we can free partially populated slots safely, free every
temporary cgroup before returning on error, and only after a successful
conversion free the original list (including the pointer array) before
swapping in the new one. With these guards in place the ASan leak report
is gone.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>1 parent b119f71 commit 440f57f
1 file changed
+16
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
829 | | - | |
| 829 | + | |
| 830 | + | |
830 | 831 | | |
| 832 | + | |
| 833 | + | |
831 | 834 | | |
832 | 835 | | |
833 | 836 | | |
| |||
843 | 846 | | |
844 | 847 | | |
845 | 848 | | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
856 | 853 | | |
857 | | - | |
| 854 | + | |
| 855 | + | |
858 | 856 | | |
859 | 857 | | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
860 | 864 | | |
861 | 865 | | |
862 | 866 | | |
| |||
0 commit comments