Mysql UDF에 대해 Valgrind로 memory leak를 테스트 해보니까 잘 못 찾는 거 같은데요?
안녕하세요, 제가 LINUX에서 C로 라이브러리를 만들고 Mysql UDF를 만들었습니다.
1. c로 쉐어드라이브러리를 만듬(my_function.c --> mysql_my_function.so)
// gcc -g 옵션으로 컴파일
2. CREATE FUNCTION my_function RETURNS STRING SONAME 'mysql_my_function.so';
3. wrapper 함수: CREATE FUNCTION user_function안에서 다시 my_function을 호출하여 사용.
이런 상황에서 메모리 릭을 검사하기 위해 my_function.c에 대해 valgrind로
(valgrind --tool=memcheck --leak-check=full) 체크해보니 메모리 릭이 하나 나옵니다.
(일부러 나오게 해봤음)
그런데 shell script로 아래와 같이 valgrind로 테스트 해보니 메모리 릭이 하나도 않나옵니다.
(오라클쪽도 마찬가지)
1. 테스트를 위한 shell scrpit test.sh
#!/bin/bash
mysql -uroot -pxxxxx db명 < mysql_func.sql
2. mysql_func.sql
select user_function(, , ,) from dual;
3. valgrind --tool=memcheck --leak-check=full ./test.sh
결과가 메모리 릭이 나와야 하는데 않나옵니다.
이렇게 오라클이나 mysql에서 사용하는 함수와 연결된 라이브러리에 대한 메모리 릭은
valgrind가 못 찾아주나요?
무슨 방법이 없는지요? 고수님의 도움을 바랍니다.
감사합니다.
...
저렇게 하면 디폴트로 valgrind는 셸 스크립트에 대한 체크만 수행하고 스크립트가 만드는 subprocess는 건드리지 않습니다.
--trace-children=yes를 줘보세요.
아래는 매뉴얼에서:
--trace-children= [default: no]
When enabled, Valgrind will trace into sub-processes initiated via the exec system call. This is necessary for multi-process programs.
Note that Valgrind does trace into the child of a fork (it would be difficult not to, since fork makes an identical copy of a process), so this option is arguably badly named. However, most children of fork calls immediately call exec anyway.
추가: 음 다시 읽어보니 memory leak이 발생하는 함수가 mysql 서버 쪽에 링크되어서 쓰이는 것 같은데, 그러면 당연히 client 쪽에서는 메모리 릭이 발생하지 않으니 valgrind를 돌려도 찾을 수가 없지요. mysql 서버를 valgrind로 실행시키셔야...
댓글 달기