malloc: *** error for object: pointer being freed was not allocated
chrisozenne opened this issue · comments
I'm getting the following error when connecting to redis from my Kitura project:
myFirstProject(78932,0x700000187000) malloc: *** error for object 0x7fb2fb602d50: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
I get a response back from the request, however the server crashes after the request has been served. I think this has to do with the deinit of reds, but I am not sure how to debug.
Here's the code:
router.get("/visits", handler: {
request, response, next in
let redis = Redis()
redis.connect("localhost", port: 6379, callback: { (error: NSError?) in
if let error = error {
Log.verbose(error.localizedDescription)
} else {
redis.incr("visits", by: 1, callback: { (visits: Int?, error: NSError?) in
if let error = error {
Log.verbose(error.localizedDescription)
} else {
if let visits = visits {
response.status(HttpStatusCode.OK).send("Visits: \(visits)")
next()
}
}
})
}
})
})
The issue is indeed in the deinit of the code, in particular in the call to redisFree, which closes the connection and frees the allocated memory.
I don't have a solution yet.
I now finally have solved this issue.
I removed our dependency on Hiredis and replaced it with a pure swift implementation of the REdis Serialization Protocol (RESP). This code is found in our develop branch. To use it you must:
1. Upgrade to the 05/03 drop of Swift
2. In your Package.swift file, update:
- The minor of Kitura to13.
- The minor of Kitura-redis to 13.
- If present, the minor of HeliumLogger to 7.
**Note:** You may have to update other dependencies as well, depending on what is in your Package.swift file
- Do an rm -rf .build Kitura-Build Packages
- Do a make run
Please note that the migration of Kitura and it's associated packages is still work in progress. Not all of the packages have been migrated yet.