1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| # 在 node1 的 root 目录中有一个压缩包,名为 application.tgz 包含了一个 client-server应用程序。
# 这些程序都被设计为在同一个系统上使用client 应用程序能够接受键盘输入并且发到服务器,输入 ctrl-D,将结束客户端程序。
# 服务端应用程序做的事情一样: 它们接受来自 client 的输入并且复制到文件/tmp/application.out.一旦进入生产环节,
# 服务端应用程序将会运行很长时间而不能重新启动,并且每天需要处理数百个连接请求。你必须分析服务端应用程序,将答案填写在下方:
# 这个应用存在什么问题?
# 这是一道选择题,数据内存泄漏 memory leak [两个空,一个填memory 一个填leak]
[root@node1 ~]# tar xf application.tgz
[root@node1 ~]# valgrind --tool=memcheck ./server
==33070== Memcheck, a memory error detector
==33070== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==33070== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==33070== Command: ./server
==33070==
^C==33070==
==33070== Process terminating with default action of signal 2 (SIGINT)
==33070== at 0x4F43D48: accept (in /usr/lib64/libc-2.28.so)
==33070== by 0x400842: main (in /root/server)
==33070==
==33070== HEAP SUMMARY:
==33070== in use at exit: 196,608 bytes in 4 blocks
==33070== total heap usage: 4 allocs, 0 frees, 196,608 bytes allocated
==33070==
==33070== LEAK SUMMARY:
==33070== definitely lost: 196,608 bytes in 4 blocks
==33070== indirectly lost: 0 bytes in 0 blocks
==33070== possibly lost: 0 bytes in 0 blocks
==33070== still reachable: 0 bytes in 0 blocks
==33070== suppressed: 0 bytes in 0 blocks
==33070== Rerun with --leak-check=full to see details of leaked memory
==33070==
==33070== For lists of detected and suppressed errors, rerun with: -s
==33070== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
#=================================================================================
[root@node1 ~]# ./client
Type ctrl-D to exit this utility.
pwd
123
|