sqlite3_exec是否存在内存泄漏? [英] sqlite3_exec is there a memory leak?

查看:814
本文介绍了sqlite3_exec是否存在内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQLite存储数据.我正在写包装器类,我想知道:如果(res!= SQLITE_OK)和errorMsg会显示在屏幕上,将导致内存泄漏?

I'm using SQLite to store my data. I'm writing wrapper class, and I want to know: will be a memory leak if (res != SQLITE_OK) and errorMsg will be displayed to the screen??

所以我需要做free(errorMsg);在如果"陈述中?谢谢!

So do I need to do free(errorMsg); in the "if" statement? Thanx!

-(int) executeQuery: (NSString *) sqlQueryStr
{
char *errorMsg = NULL;
int res = SQLITE_ERROR;

res = sqlite3_exec(database, [sqlQueryStr UTF8String], NULL, NULL, &errorMsg);

if (res != SQLITE_OK)
{
    sqlite3_close(database); 
    NSLog(@"executeQuery Error:  %@", errorMsg);
    database = NULL;
    return res;
}

return res;
}

推荐答案

根据

为避免内存泄漏,该应用程序 应该在错误时调用sqlite3_free() 通过返回的消息字符串 sqlite3_exec()的第五个参数 错误消息字符串为no之后 需要更长的时间.

To avoid memory leaks, the application should invoke sqlite3_free() on error message strings returned through the 5th parameter of of sqlite3_exec() after the error message string is no longer needed.

这篇关于sqlite3_exec是否存在内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆