(if (bufferp (get-file-buffer filename))
(setq found (buffer-file-name (get-file-buffer filename))))
The problem is that this always fails, and found will always be nil. The filename constructed is not being expanded, as get-file-buffer demands. However, expanding it is useless, since the exact expansion (absolute path) of the searched file is not exactly known! However, you can rework these lines to just look for a buffer whose name matches the file you are looking for:
(let ((b (find-if (lambda(x) (string= (buffer-name x) filename)) (buffer-list))))
(setq found (buffer-file-name b))))
Note that this will only do a simple string matching. It might happen that for a certain file foo.cc you have to buffers visiting some foo.h. The function will only find the first one. But in my opinion, there is not simple solution to find the semantically correct header file, anyway. So this is still better than the broken solution in Emacs.