Yes there are problems - you forgot to delete b and have a memory leak.
Also if(b) is useless since new will throw bad_alloc if there is not enough memory.
Class A doesn't have a method setX.
There is no way that getA() could possibly return a null pointer. The object from B must of course be valid but checking the result of getA() doesn't make sense nonetheless.
In the above code is there any case where getA() can return a NULL pointer or invalid pointer.
The simple answer is no, as long as b is valid.
The longer answer is if b is not valid, then any reference returned by getA() is also invalid and will result in undefined behavior.
Consider:
1 2 3 4 5
B * b = new B;
// Do something with b
delete b;
b = nullptr;
// b is no longer valid
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.