vapor-community / postgresql-provider

PostgreSQL Provider for the Vapor web framework.
MIT License
70 stars 19 forks source link

Memory leak on saving datamodels #35

Closed dev-affective-de closed 6 years ago

dev-affective-de commented 6 years ago

When a datamodel is saved, the memory allocated by PostgreSQL Connection.swift public func execute(_ query: String, _ values: [Node] = []) throws -> Node call to extension Node public func bind(with configuration: Configuration) -> Bind is not released.

For testing I changed the function PostgreSQL Connection.swift execute to:

    @discardableResult
    public func execute(_ query: String, _ values: [Node] = []) throws -> Node {
        let binds = values.map { $0.bind(with: configuration) }
        let res = try execute(query, binds)

        for i in 0..<binds.count {
            // free the by bind allocated memory
            binds[i].bytes?.deallocate(capacity: (values[i].string?.count)!)
        }

    return res
    }

I'm not sure if that works fine in all cases. Specially I'm not sure if I find the right capacity. But it looks like the bug is fixed.

vzsg commented 6 years ago

I just tagged vapor-community/postgresql version 2.1.1 that fixes the same memory leak cleaner on a lower level. Please try updating to it and see if it works for you too.

dev-affective-de commented 6 years ago

Hello vzsg,

your fix works fine. Many thanks.