diff --git a/ChangeLog b/ChangeLog index 419645a..ed678c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,14 @@ +2017-04-07 Richard Frith-Macdonald + + * SQLClient.m: + Fix leak of SQLString instances caused by inheriting memory management + methods from the literal string class. + 2017-03-06 Richard Frith-Macdonald - SQLClient.h: - SQLClient.m: - SQLClientPool.m: + * SQLClient.h: + * SQLClient.m: + * SQLClientPool.m: Add new +literal: and -literal: methods to make a normal string into one recognised as suitable for use literally (ie without quoting) in an SQL query/statement. diff --git a/SQLClient.m b/SQLClient.m index cd39303..2eb28cd 100644 --- a/SQLClient.m +++ b/SQLClient.m @@ -992,6 +992,8 @@ static int poolConnections = 0; if (Nil == LitStringClass) { + Class root = [NSObject class]; + /* Find the literal string class used by the foundation library. */ LitStringClass = object_getClass(@"test"); @@ -1001,6 +1003,22 @@ static int poolConnections = 0; SQLStringClass = (Class)objc_allocateClassPair( LitStringClass, "SQLString", 0); objc_registerClassPair(SQLStringClass); + + /* The the NSObject memory management methods because the + * literal string doesn't get retained/released. + */ + class_replaceMethod(SQLStringClass, @selector(retain), + class_getMethodImplementation(root, @selector(retain)), + "@@:"); + class_replaceMethod(SQLStringClass, @selector(autorelease), + class_getMethodImplementation(root, @selector(autorelease)), + "@@:"); + class_replaceMethod(SQLStringClass, @selector(release), + class_getMethodImplementation(root, @selector(release)), + "v@:"); + class_replaceMethod(SQLStringClass, @selector(dealloc), + class_getMethodImplementation(root, @selector(dealloc)), + "v@:"); } if (nil == null)