objective c - Leak when calling SSL_connect -


i using openssl , according instruments, have memory leak started @ ssl_connect.

ssl_ctx *ctx = ssl_ctx_new(sslv23_method()); if (!ctx) {     nslog(@"could not initialize ctx");     [self release];     return nil; } if(!ssl_ctx_use_certificate_chain_file(ctx, [pemfile utf8string])) {     nslog(@"can't read certificate file");     [self release];     return nil; } if(!(ssl_ctx_use_privatekey_file(ctx, [pemfile utf8string], ssl_filetype_pem))) {     nslog(@"can't read key file");     [self release];     return nil; }  _sock = [self _tcpconnectwithhost:host port:port]; if (_sock < 0) {     [self release];     return nil; } _sslpointer = ssl_new(ctx); bio *bio = bio_new_socket(sock, bio_noclose); ssl_set_bio(_sslpointer, bio, bio); if(ssl_connect(_sslpointer) <= 0) {     nslog(@"ssl connect error");     [self release];     return nil; }  ssl_ctx_free(ctx); 

i release when dealloc called. when leak appears.

ssl_free(_sslpointer); close(_sock); 

call stack leak starts is:

0 libsystem.b.dylib malloc 1 libcrypto.0.9.8.dylib crypto_malloc 2 libcrypto.0.9.8.dylib asn1_item_ex_combine_new 3 libcrypto.0.9.8.dylib asn1_item_ex_d2i 4 libcrypto.0.9.8.dylib asn1_template_noexp_d2i 5 libcrypto.0.9.8.dylib asn1_template_ex_d2i 6 libcrypto.0.9.8.dylib asn1_item_ex_d2i 7 libcrypto.0.9.8.dylib asn1_template_noexp_d2i 8 libcrypto.0.9.8.dylib asn1_template_ex_d2i 9 libcrypto.0.9.8.dylib asn1_item_ex_d2i 10 libcrypto.0.9.8.dylib x509_name_ex_d2i 11 libcrypto.0.9.8.dylib asn1_item_ex_d2i 12 libcrypto.0.9.8.dylib asn1_template_noexp_d2i 13 libcrypto.0.9.8.dylib asn1_template_ex_d2i 14 libcrypto.0.9.8.dylib asn1_item_ex_d2i 15 libcrypto.0.9.8.dylib asn1_template_noexp_d2i 16 libcrypto.0.9.8.dylib asn1_template_ex_d2i 17 libcrypto.0.9.8.dylib asn1_item_ex_d2i 18 libcrypto.0.9.8.dylib asn1_item_d2i 19 libssl.0.9.8.dylib ssl3_get_server_certificate 20 libssl.0.9.8.dylib ssl3_connect 21 libssl.0.9.8.dylib ssl23_connect 

the obvious thing see you're ever freeing ssl_ctx *ctx if works out ok. have whole bunch of possible exits before ctx has been created, never free() it.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -