- This is something I've thought about for a very long time. And it was probably the main reason why Mary Fairbrother never really liked the Fields, because his illegimate daughter lived there. And it was even more reason why she was upset when she realized that after Krystal died and would be buried next to Barry, Mary just wanted to leave. It makes even more sense when you look at the series.
The motive is obvious: he had fallen in love with Mary Fairbrother, and, furthermore, Kay Bawden had come to town and Gavin was not able to cope with it, and he desperately wanted out. He needed to get Barry out of the way so he could get Mary and ditch Kay. Especially given Kay's incorrigibility, this was enough to push Gavin to the limit and into acting out.
Gavin had a perfect opportunity to do it. Gavin had played squash with Barry a few days before Barry died. Barry, of course, would have brought something to drink along. It would have been very simple for Gavin to spike his drink with a drug that could have provoked the aneurysm. (We might note that this is a really ineffective way to murder someone, but keep in mind Gavin's personality: paranoid and completely lacking assertiveness. He would naturally gravitate toward the most innocuous murder weapon possible, one that happened to work probably only because Barry had a condition it exacerbated.)
How did Gavin do this, but then never think about it afterwards? Simple: he doesn't remember. Gavin has a talent for dissociating. Utterly lacking assertiveness, going into an dissociative state is the only way he is able to act out. There is evidence for this. We see him have memory lapses several times throughout the book, such as not knowing who people are despite clearly being as on top of town gossip as anyone. One time he explicitly fails to remember something that definitely happened: seeing Robbie right before he fell in the river, which is not something a normal person is likely to forget. Gavin has no memory of it despite the fact that he looked directly at the child, just like he had no memory of killing Barry Fairbrother despite the fact that he did it.
Other clues include his mental slip near the end of the book. After Mary rejected him, Gavin thought to himself, "That's what you get for trying to steal your best friend's life." The author explicitly calls it a slip, and alert readers will realize it's not just metaphorical. Obviously some of Gavin's repressed memories slipped out there. Other clues include the fact that Colin Walls dreamt about poisoning Barry, the exact method Gavin used. This is not because Colin Walls has prophetic dreams—there's no evidence that this is that kind of universe—so much as foreshadowing the later revelation that Gavin took his friend's life. (Though it's possible that Colin unconciously absorbed and pieced together the truth from the town gossip and it worked its way out in a dream.)