return (size + 1_MB - 1) / 1_MB;
}
+void ClearApp2ExtDirDetail(gpointer data) {
+ app2ext_dir_details* dir_detail =
+ reinterpret_cast<app2ext_dir_details*>(data);
+ if (dir_detail->name)
+ free(dir_detail->name);
+ free(dir_detail);
+}
+
} // namespace
namespace common_installer {
for (auto& dir : external_dirs_) {
app2ext_dir_details* dir_detail = reinterpret_cast<app2ext_dir_details*>(
calloc(1, sizeof(app2ext_dir_details)));
+ if (!dir_detail) {
+ LOG(ERROR) << "Out of memory";
+ g_list_free_full(glist, &ClearApp2ExtDirDetail);
+ return false;
+ }
dir_detail->name = strdup(dir.c_str());
+ if (!dir_detail->name) {
+ LOG(ERROR) << "Out of memory";
+ free(dir_detail);
+ g_list_free_full(glist, &ClearApp2ExtDirDetail);
+ return false;
+ }
dir_detail->type = APP2EXT_DIR_RO;
glist = g_list_append(glist, dir_detail);
}
assert(false && "Invalid installation mode");
}
- g_list_free_full(glist, [](gpointer data) {
- app2ext_dir_details* dir_detail =
- reinterpret_cast<app2ext_dir_details*>(data);
- free(dir_detail->name);
- free(dir_detail);
- });
+ g_list_free_full(glist, &ClearApp2ExtDirDetail);
return ret == 0;
}
void ClearMetadataDetail(gpointer data) {
__metadata_t* meta = reinterpret_cast<__metadata_t*>(data);
- free(const_cast<char*>(meta->key));
- free(const_cast<char*>(meta->value));
+ if (meta->key)
+ free(const_cast<char*>(meta->key));
+ if (meta->value)
+ free(const_cast<char*>(meta->value));
free(meta);
}
std::string(meta->key).find(sub_key_prefix) == 0) {
__metadata_t* md = reinterpret_cast<__metadata_t*>(
calloc(1, sizeof(__metadata_t)));
+ if (!md) {
+ LOG(ERROR) << "Out of memory";
+ g_list_free_full(md_list, &ClearMetadataDetail);
+ return false;
+ }
md->key = strdup(meta->key);
+ if (!md->key) {
+ LOG(ERROR) << "Out of memory";
+ free(md);
+ g_list_free_full(md_list, &ClearMetadataDetail);
+ return false;
+ }
md->value = strdup(meta->value);
+ if (!md->value) {
+ LOG(ERROR) << "Out of memory";
+ ClearMetadataDetail(md);
+ g_list_free_full(md_list, &ClearMetadataDetail);
+ return false;
+ }
md_list = g_list_append(md_list, md);
}
}
for (auto& pair : pkg_info->labels()) {
label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+ if (!label) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
if (!pair.first.empty())
label->lang = strdup(pair.first.c_str());
else
return true;
author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
+ if (!author) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
author->text = strdup(author_info->name().c_str());
author->email = strdup(author_info->email().c_str());
author->href = strdup(author_info->href().c_str());
for (auto& desc : description_info->descriptions) {
description_x* description = reinterpret_cast<description_x*>
(calloc(1, sizeof(description_x)));
+ if (!description) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
description->text = strdup(desc.description().c_str());
description->lang = !desc.xml_lang().empty() ?
strdup(desc.xml_lang().c_str()) : strdup(DEFAULT_LOCALE);
for (auto& priv : privileges) {
privilege_x* privilege =
reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+ if (!privilege) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
privilege->value = strdup(priv.first.c_str());
privilege->type = strdup(priv.second.c_str());
manifest->privileges = g_list_append(manifest->privileges, privilege);
application_x* widget_app =
static_cast<application_x*>(calloc(1, sizeof(application_x)));
+ if (!widget_app) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
widget_app->appid = strdup(application.app_info.appid().c_str());
widget_app->launch_mode =
strdup(application.app_info.launch_mode().c_str());
application_x* service_app =
static_cast<application_x*>(calloc(1, sizeof(application_x)));
+ if (!service_app) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
service_app->appid = strdup(application.app_info.appid().c_str());
service_app->multiple = strdup(application.app_info.multiple().c_str());
service_app->taskmanage = strdup(application.app_info.taskmanage().c_str());
application_x* ui_app =
static_cast<application_x*>(calloc(1, sizeof(application_x)));
+ if (!ui_app) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
ui_app->appid = strdup(application.app_info.appid().c_str());
ui_app->launch_mode = strdup(application.app_info.launch_mode().c_str());
ui_app->multiple = strdup(application.app_info.multiple().c_str());
application_x* watch_app =
static_cast<application_x*>(calloc(1, sizeof(application_x)));
+ if (!watch_app) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
watch_app->appid = strdup(watch_application.app_info.appid().c_str());
if (bf::path(watch_application.app_info.exec().c_str()).is_absolute())
for (const auto& control : app_control_list) {
appcontrol_x* app_control =
static_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
+ if (!app_control) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
app_control->operation = strdup(control.operation().c_str());
if (!control.mime().empty())
app_control->mime = strdup(control.mime().c_str());
for (const auto& control : data_control_list) {
datacontrol_x* data_control =
static_cast<datacontrol_x*>(calloc(1, sizeof(datacontrol_x)));
+ if (!data_control) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
data_control->access = strdup(control.access().c_str());
data_control->providerid = strdup(control.providerid().c_str());
data_control->type = strdup(control.type().c_str());
bool StepParseManifest::FillApplicationIconPaths(application_x* app,
const T& icons_info) {
for (auto& application_icon : icons_info.icons()) {
- icon_x* icon = reinterpret_cast<icon_x*> (calloc(1, sizeof(icon_x)));
+ icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
+ if (!icon) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
bf::path text;
if (bf::path(application_icon.path()).is_absolute()) {
text = application_icon.path();
for (const auto& control : label_list) {
label_x* label =
static_cast<label_x*>(calloc(1, sizeof(label_x)));
+ if (!label) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
// NOTE: name is an attribute, but the xml writer uses it as text.
// This must be fixed in whole app-installer modules, including wgt.
// Current implementation is just for compatibility.
for (auto& meta : meta_data_list) {
metadata_x* metadata =
static_cast<metadata_x*>(calloc(1, sizeof(metadata_x)));
+ if (!metadata) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
metadata->key = strdup(meta.key().c_str());
metadata->value = strdup(meta.val().c_str());
app->metadata = g_list_append(app->metadata, metadata);
const std::string& operation, const std::string& color_depth) {
splashscreen_x* splashscreen =
static_cast<splashscreen_x*>(calloc(1, sizeof(splashscreen_x)));
+ if (!splashscreen) {
+ LOG(ERROR) << "Out of memory";
+ return;
+ }
if (bf::path(src).is_absolute()) {
splashscreen->src = strdup(src.c_str());
} else {
for (auto& app_image : image_list.images) {
image_x* image =
static_cast<image_x*>(calloc(1, sizeof(image_x)));
+ if (!image) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
const std::string& lang = app_image.lang();
if (!lang.empty())
image->lang = strdup(lang.c_str());
manifest_x* manifest =
static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
+ if (!manifest) {
+ LOG(ERROR) << "Out of memory";
+ return Step::Status::ERROR;
+ }
if (!FillManifestX(const_cast<manifest_x*>(manifest))) {
LOG(ERROR) << "[Parse] Storing manifest_x failed. "
internal_priv_type_ == InternalPrivType::BOTH) {
privilege_x* privilege =
reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+ if (!privilege) {
+ LOG(ERROR) << "Out of memory";
+ return Step::Status::ERROR;
+ }
privilege->type = strdup(kNativePrivilegeType);
privilege->value = strdup(internal_priv.c_str());
context_->manifest_data.get()->privileges =
internal_priv_type_ == InternalPrivType::BOTH) {
privilege_x* privilege =
reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+ if (!privilege) {
+ LOG(ERROR) << "Out of memory";
+ return Step::Status::ERROR;
+ }
privilege->type = strdup(kWebPrivilegeType);
privilege->value = strdup(internal_priv.c_str());
context_->manifest_data.get()->privileges =
if (context_->debug_mode.get()) {
privilege_x* privilege =
reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+ if (!privilege) {
+ LOG(ERROR) << "Out of memory";
+ return Step::Status::ERROR;
+ }
privilege->type = internal_priv_type_ == InternalPrivType::TPK ?
strdup(kNativePrivilegeType) : strdup(kWebPrivilegeType);
privilege->value = strdup(kAppDebuggingPrivilegeStr);