"SELECT width, height FROM support_size WHERE classid=?";
int ret;
sqlite3 *db;
- sqlite3_stmt *stmt;
+ sqlite3_stmt *stmt = NULL;
int count = 0;
int i;
- int *width;
- int *height;
+ int *width = NULL;
+ int *height = NULL;
db = _open_db(uid);
if (db == NULL)
if (ret != SQLITE_OK) {
/* LCOV_EXCL_START */
_E("prepare error: %s", sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- return WIDGET_ERROR_FAULT;
+ ret = WIDGET_ERROR_FAULT;
+ goto err;
/* LCOV_EXCL_STOP */
}
count++;
if (count == 0) {
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
*cnt = 0;
*w = NULL;
*h = NULL;
- return WIDGET_ERROR_NOT_EXIST;
+ ret = WIDGET_ERROR_NOT_EXIST;
+ goto err;
}
sqlite3_reset(stmt);
width = malloc(sizeof(int) * count);
+ if (!width) {
+ _E("Failed to allocate width");
+ ret = WIDGET_ERROR_FAULT; /* It shoud be WIDGET_ERROR_OUT_OF_MEMORY */
+ goto err;
+ }
+
height = malloc(sizeof(int) * count);
+ if (!height) {
+ _E("Failed to allocate height");
+ ret = WIDGET_ERROR_FAULT; /* It should be WIDGET_ERROR_OUT_OF_MEMORY */
+ goto err;
+ }
for (i = 0; i < count; i++) {
- sqlite3_step(stmt);
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ _E("sqlite3_step() is failed. err(%s)",
+ sqlite3_errmsg(db));
+ ret = WIDGET_ERROR_FAULT;
+ goto err;
+ }
_get_column_int(stmt, 0, &width[i]);
_get_column_int(stmt, 1, &height[i]);
}
if (_convert_to_support_size(width, height, count)) {
_E("failed to convert size");
- free(width);
- free(height);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return WIDGET_ERROR_FAULT;
+ ret = WIDGET_ERROR_FAULT;
+ goto err;
}
*w = width;
*h = height;
sqlite3_close_v2(db);
return WIDGET_ERROR_NONE;
+
+err:
+ if (height)
+ free(height);
+ if (width)
+ free(width);
+ if (stmt)
+ sqlite3_finalize(stmt);
+ if (db)
+ sqlite3_close_v2(db);
+
+ return ret;
}
"SELECT width, height FROM support_size WHERE classid=?";
int ret;
sqlite3 *db;
- sqlite3_stmt *stmt;
+ sqlite3_stmt *stmt = NULL;
int count = 0;
int i;
- int *width;
- int *height;
- int *type;
+ int *width = NULL;
+ int *height = NULL;
+ int *type = NULL;
db = _open_db(uid);
if (db == NULL)
if (ret != SQLITE_OK) {
/* LCOV_EXCL_START */
_E("prepare error: %s", sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- return WIDGET_ERROR_FAULT;
+ ret = WIDGET_ERROR_FAULT;
+ goto err;
/* LCOV_EXCL_STOP */
}
count++;
if (count == 0) {
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
*cnt = 0;
*w = NULL;
*h = NULL;
- return WIDGET_ERROR_NOT_EXIST;
+ ret = WIDGET_ERROR_NOT_EXIST;
+ goto err;
}
sqlite3_reset(stmt);
width = malloc(sizeof(int) * count);
+ if (!width) {
+ _E("Failed to allocate width");
+ ret = WIDGET_ERROR_FAULT; /* It should be WIDGET_ERROR_OUT_OF_MEMORY */
+ goto err;
+ }
+
height = malloc(sizeof(int) * count);
+ if (!height) {
+ _E("Failed to allocate height");
+ ret = WIDGET_ERROR_FAULT; /* It should be WIDGET_ERROR_OUT_OF_MEMORY */
+ goto err;
+ }
+
type = malloc(sizeof(int) * count);
+ if (!type) {
+ _E("Failed to allocate type");
+ ret = WIDGET_ERROR_FAULT; /* It should be WIDGET_ERROR_OUT_OF_MEMORY */
+ goto err;
+ }
for (i = 0; i < count; i++) {
- sqlite3_step(stmt);
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ _E("sqlite3_step() is failed. err(%s)",
+ sqlite3_errmsg(db));
+ ret = WIDGET_ERROR_FAULT;
+ goto err;
+ }
_get_column_int(stmt, 0, &width[i]);
_get_column_int(stmt, 1, &height[i]);
}
if (_convert_to_support_info(width, height, type, count)) {
_E("failed to convert size");
- free(width);
- free(height);
- free(type);
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
- return WIDGET_ERROR_FAULT;
+ ret = WIDGET_ERROR_FAULT;
+ goto err;
}
*t = type;
*w = width;
sqlite3_close_v2(db);
return WIDGET_ERROR_NONE;
+
+err:
+ if (type)
+ free(type);
+ if (height)
+ free(height);
+ if (width)
+ free(width);
+ if (stmt)
+ sqlite3_finalize(stmt);
+ if (db)
+ sqlite3_close_v2(db);
+
+ return ret;
}
/* LCOV_EXCL_START */