Created
February 27, 2013 16:25
-
-
Save labeneator/5049227 to your computer and use it in GitHub Desktop.
GDB for loop to close leaky fds
This file contains hidden or 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
Leaks all over the place | |
$ lsof -p $(pgrep leaky) | |
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME | |
leaky 16095 laban cwd DIR 0,30 4096 10936796 /home/laban/devel/private/learning/c/leak_descriptors | |
leaky 16095 laban rtd DIR 252,1 4096 2 / | |
leaky 16095 laban txt REG 0,30 11267 10919599 /home/laban/devel/private/learning/c/leak_descriptors/leaky | |
leaky 16095 laban mem REG 252,1 1811128 19136595 /lib/x86_64-linux-gnu/libc-2.15.so | |
leaky 16095 laban mem REG 252,1 149280 19136932 /lib/x86_64-linux-gnu/ld-2.15.so | |
leaky 16095 laban 0u CHR 136,19 0t0 22 /dev/pts/19 | |
leaky 16095 laban 1u CHR 136,19 0t0 22 /dev/pts/19 | |
leaky 16095 laban 2u CHR 136,19 0t0 22 /dev/pts/19 | |
leaky 16095 laban 3r REG 252,1 2667 1575354 /etc/passwd | |
leaky 16095 laban 4r REG 252,1 2667 1575354 /etc/passwd | |
leaky 16095 laban 5r REG 252,1 1210 1575723 /etc/group | |
leaky 16095 laban 6r REG 252,1 1210 1575723 /etc/group | |
leaky 16095 laban 7r REG 252,1 1210 1575723 /etc/group | |
leaky 16095 laban 8r REG 252,1 1210 1575723 /etc/group | |
GDB closing fds | |
$ sudo gdb -p $(pgrep leaky) | |
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04 | |
Copyright (C) 2012 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
This is free software: you are free to change and redistribute it. | |
There is NO WARRANTY, to the extent permitted by law. Type "show copying" | |
and "show warranty" for details. | |
This GDB was configured as "x86_64-linux-gnu". | |
For bug reporting instructions, please see: | |
<http://bugs.launchpad.net/gdb-linaro/>. | |
Attaching to process 16095 | |
Reading symbols from /home/laban/devel/private/learning/c/leak_descriptors/leaky...done. | |
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.15.so...done. | |
done. | |
Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6 | |
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.15.so...done. | |
done. | |
Loaded symbols for /lib64/ld-linux-x86-64.so.2 | |
0x00007f253e7cf820 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:82 | |
82 ../sysdeps/unix/syscall-template.S: No such file or directory. | |
(gdb) set $max=8 | |
(gdb) set $current=3 | |
(gdb) while ($current < $max) | |
> p close($current++) | |
>end | |
$5 = -1 | |
$6 = 0 | |
$7 = 0 | |
$8 = 0 | |
$9 = 0 | |
(gdb) ^Z | |
[2]+ Stopped sudo gdb -p $(pgrep leaky) | |
What lsof thinks after GDB's done | |
$ lsof -p $(pgrep leaky) | |
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME | |
leaky 16095 laban cwd DIR 0,30 4096 10936796 /home/laban/devel/private/learning/c/leak_descriptors | |
leaky 16095 laban rtd DIR 252,1 4096 2 / | |
leaky 16095 laban txt REG 0,30 11267 10919599 /home/laban/devel/private/learning/c/leak_descriptors/leaky | |
leaky 16095 laban mem REG 252,1 1811128 19136595 /lib/x86_64-linux-gnu/libc-2.15.so | |
leaky 16095 laban mem REG 252,1 149280 19136932 /lib/x86_64-linux-gnu/ld-2.15.so | |
leaky 16095 laban 0u CHR 136,19 0t0 22 /dev/pts/19 | |
leaky 16095 laban 1u CHR 136,19 0t0 22 /dev/pts/19 | |
leaky 16095 laban 2u CHR 136,19 0t0 22 /dev/pts/19 | |
leaky 16095 laban 8r REG 252,1 1210 1575723 /etc/group | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment