From 4ecbc44f79b38cadfe73d79a9785d9995f17c792 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Thu, 16 Oct 2014 02:08:11 +0000 Subject: [PATCH] Fix a potential null pointer deref & a potential memory leak, also reformat to conform to the usual lldb coding conventions a little better. clang static analyzer fixit. llvm-svn: 219893 --- lldb/source/Host/macosx/launcherXPCService/main.mm | 80 +++++++++++++++------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/lldb/source/Host/macosx/launcherXPCService/main.mm b/lldb/source/Host/macosx/launcherXPCService/main.mm index 768faef..397d3a5 100644 --- a/lldb/source/Host/macosx/launcherXPCService/main.mm +++ b/lldb/source/Host/macosx/launcherXPCService/main.mm @@ -23,7 +23,8 @@ int _validate_authorization(xpc_object_t message); // Returns 0 if successful. -int _setup_posixspawn_attributes_file_actions(xpc_object_t message, posix_spawnattr_t *attr, posix_spawn_file_actions_t *file_actions) +int +_setup_posixspawn_attributes_file_actions(xpc_object_t message, posix_spawnattr_t *attr, posix_spawn_file_actions_t *file_actions) { *attr = 0; @@ -32,7 +33,8 @@ int _setup_posixspawn_attributes_file_actions(xpc_object_t message, posix_spawna return errorCode; cpu_type_t cpuType = (cpu_type_t)xpc_dictionary_get_int64(message, LauncherXPCServiceCPUTypeKey); - if (cpuType == -2) { + if (cpuType == -2) + { cpuType= CPU_TYPE_ANY; } size_t realCount; @@ -94,23 +96,27 @@ int _setup_posixspawn_attributes_file_actions(xpc_object_t message, posix_spawna return errorCode; } -bool extract_args(xpc_object_t message, const char *prefix, const char ***argsOut) +bool +extract_args(xpc_object_t message, const char *prefix, const char ***argsOut) { char buf[50]; // long enough for 'argXXX' memset(buf, 0, 50); sprintf(buf, "%sCount", prefix); int argsCount = (int)xpc_dictionary_get_int64(message, buf); - if (argsCount == 0) { + if (argsCount == 0) + { return true; } const char **argsp = NULL; argsp = (const char **)malloc((argsCount+1) * sizeof(argsp[0])); - if (argsp == NULL) { + if (argsp == NULL) + { return false; } - for (int i=0; i