From: OpenOCD-Gerrit <ope...@us...> - 2021-05-01 12:38:20
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 1e5782a09a149fe106fa2e574482108f730e4beb (commit) via 4622a95fcc470d0c1a086ba046abe1f63b139750 (commit) via 89c6b93ba278e26113aadcc3b7d357e05264beba (commit) from f18a801e03e50274676544d10029c05e1f219246 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 1e5782a09a149fe106fa2e574482108f730e4beb Author: Antonio Borneo <bor...@gm...> Date: Sun Apr 25 23:15:36 2021 +0200 jtag: simplify the calls to Jim_SetResultFormatted() The documentation of Jim_SetResultFormatted() reports that the jim objects passed as arguments would be freed if have zero refcount. Remove the useless Jim_IncrRefCount()/Jim_DecrRefCount(). Remove the dangerous Jim_FreeNewObj() that should trigger a double free(). Not tested due to lack of aice adapter. While there, rename some CamelCase symbol. Change-Id: Ic56704c83d6391c38f6b0efa6566784d453bc0fb Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/6190 Tested-by: jenkins Reviewed-by: Tomas Vanek <va...@fb...> diff --git a/src/jtag/aice/aice_transport.c b/src/jtag/aice/aice_transport.c index ea710ad25..e3d431b2e 100644 --- a/src/jtag/aice/aice_transport.c +++ b/src/jtag/aice/aice_transport.c @@ -255,9 +255,8 @@ static int jim_aice_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj * const e = aice_init_reset(context); if (e != ERROR_OK) { - Jim_Obj *eObj = Jim_NewIntObj(goi.interp, e); - Jim_SetResultFormatted(goi.interp, "error: %#s", eObj); - Jim_FreeNewObj(goi.interp, eObj); + Jim_Obj *obj = Jim_NewIntObj(goi.interp, e); + Jim_SetResultFormatted(goi.interp, "error: %#s", obj); return JIM_ERR; } return JIM_OK; diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 3e7333515..8a52c0f18 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -687,10 +687,8 @@ static int jim_jtag_arp_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv) struct command_context *context = current_command_context(interp); int e = jtag_init_inner(context); if (e != ERROR_OK) { - Jim_Obj *eObj = Jim_NewIntObj(goi.interp, e); - Jim_IncrRefCount(eObj); - Jim_SetResultFormatted(goi.interp, "error: %#s", eObj); - Jim_DecrRefCount(goi.interp, eObj); + Jim_Obj *obj = Jim_NewIntObj(goi.interp, e); + Jim_SetResultFormatted(goi.interp, "error: %#s", obj); return JIM_ERR; } return JIM_OK; @@ -712,10 +710,8 @@ static int jim_jtag_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj *const e = swd_init_reset(context); if (e != ERROR_OK) { - Jim_Obj *eObj = Jim_NewIntObj(goi.interp, e); - Jim_IncrRefCount(eObj); - Jim_SetResultFormatted(goi.interp, "error: %#s", eObj); - Jim_DecrRefCount(goi.interp, eObj); + Jim_Obj *obj = Jim_NewIntObj(goi.interp, e); + Jim_SetResultFormatted(goi.interp, "error: %#s", obj); return JIM_ERR; } return JIM_OK; commit 4622a95fcc470d0c1a086ba046abe1f63b139750 Author: Antonio Borneo <bor...@gm...> Date: Sun Apr 25 20:44:27 2021 +0200 helper/command: drop the TCL variable 'ocd_HOSTOS' Commit 7a731eb63731 ("Added HostOS variable"), merged in 2009, adds a TCL global variable 'ocd_HostOS' that reports in a string the OS of the host. This was proposed as a workaround for jimtcl that didn't define the standard TCL variable 'tcl_platform(os)'. With commit 42f3fb7b7f46 ("Determine platform_tcl() settings with configure"), merged in 2010 and part of jimtcl 0.70 issued in early 2011, jimtcl provides the requires TCL standard variable 'tcl_platform(os)'. The variable 'ocd_HostOS' has never been used by any TCL script distributed with OpenOCD. Drop the TCL variable 'ocd_HostOS'. Change-Id: I27858de35cc9d30df97145ca1ccd24877be4af11 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/6189 Tested-by: jenkins Reviewed-by: Tomas Vanek <va...@fb...> diff --git a/doc/openocd.texi b/doc/openocd.texi index c39e7c168..d71731138 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -11087,34 +11087,6 @@ OpenOCD commands can consist of two words, e.g. "flash banks". The @file{startup.tcl} "unknown" proc will translate this into a Tcl proc called "flash_banks". -@section OpenOCD specific Global Variables - -Real Tcl has ::tcl_platform(), and platform::identify, and many other -variables. JimTCL, as implemented in OpenOCD creates $ocd_HOSTOS which -holds one of the following values: - -@itemize @bullet -@item @b{cygwin} Running under Cygwin -@item @b{darwin} Darwin (Mac-OS) is the underlying operating system. -@item @b{freebsd} Running under FreeBSD -@item @b{openbsd} Running under OpenBSD -@item @b{netbsd} Running under NetBSD -@item @b{linux} Linux is the underlying operating system -@item @b{mingw32} Running under MingW32 -@item @b{winxx} Built using Microsoft Visual Studio -@item @b{ecos} Running under eCos -@item @b{other} Unknown, none of the above. -@end itemize - -Note: 'winxx' was chosen because today (March-2009) no distinction is made between Win32 and Win64. - -@quotation Note -We should add support for a variable like Tcl variable -@code{tcl_platform(platform)}, it should be called -@code{jim_platform} (because it -is jim, not real tcl). -@end quotation - @section Tcl RPC server @cindex RPC diff --git a/src/helper/command.c b/src/helper/command.c index 08d14b47f..0c6e785f2 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -1277,7 +1277,6 @@ static const struct command_registration command_builtin_handlers[] = { struct command_context *command_init(const char *startup_tcl, Jim_Interp *interp) { struct command_context *context = calloc(1, sizeof(struct command_context)); - const char *HostOs; context->mode = COMMAND_EXEC; @@ -1296,39 +1295,6 @@ struct command_context *command_init(const char *startup_tcl, Jim_Interp *interp context->interp = interp; - /* Stick to lowercase for HostOS strings. */ -#if defined(_MSC_VER) - /* WinXX - is generic, the forward - * looking problem is this: - * - * "win32" or "win64" - * - * "winxx" is generic. - */ - HostOs = "winxx"; -#elif defined(__linux__) - HostOs = "linux"; -#elif defined(__APPLE__) || defined(__DARWIN__) - HostOs = "darwin"; -#elif defined(__CYGWIN__) - HostOs = "cygwin"; -#elif defined(__MINGW32__) - HostOs = "mingw32"; -#elif defined(__ECOS) - HostOs = "ecos"; -#elif defined(__FreeBSD__) - HostOs = "freebsd"; -#elif defined(__NetBSD__) - HostOs = "netbsd"; -#elif defined(__OpenBSD__) - HostOs = "openbsd"; -#else -#warning "Unrecognized host OS..." - HostOs = "other"; -#endif - Jim_SetGlobalVariableStr(interp, "ocd_HOSTOS", - Jim_NewStringObj(interp, HostOs, strlen(HostOs))); - register_commands(context, NULL, command_builtin_handlers); Jim_SetAssocData(interp, "context", NULL, context); commit 89c6b93ba278e26113aadcc3b7d357e05264beba Author: Antonio Borneo <bor...@gm...> Date: Sun Apr 25 20:38:58 2021 +0200 helper/command: fix memory leak on malloc() fail If malloc() fails, the just allocated Jim_Obj will leaks. Move Jim_IncrRefCount() before the malloc() and deallocate the Jim object with Jim_DecrRefCount() on malloc() fail. While there, add the 'out of memory' log and fix the CamelCase name of the symbol tclOutput. Change-Id: Ic733db229d5aa5d477d758ea9cb88cd81d7542cd Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/6188 Tested-by: jenkins Reviewed-by: Tomas Vanek <va...@fb...> diff --git a/src/helper/command.c b/src/helper/command.c index e703be400..08d14b47f 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -83,17 +83,21 @@ static struct log_capture_state *command_log_capture_start(Jim_Interp *interp) { /* capture log output and return it. A garbage collect can * happen, so we need a reference count to this object */ - Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); - if (NULL == tclOutput) + Jim_Obj *jim_output = Jim_NewStringObj(interp, "", 0); + if (!jim_output) return NULL; + Jim_IncrRefCount(jim_output); + struct log_capture_state *state = malloc(sizeof(*state)); - if (NULL == state) + if (!state) { + LOG_ERROR("Out of memory"); + Jim_DecrRefCount(interp, jim_output); return NULL; + } state->interp = interp; - Jim_IncrRefCount(tclOutput); - state->output = tclOutput; + state->output = jim_output; log_add_callback(tcl_output, state); ----------------------------------------------------------------------- Summary of changes: doc/openocd.texi | 28 ------------------------ src/helper/command.c | 48 ++++++++---------------------------------- src/jtag/aice/aice_transport.c | 5 ++--- src/jtag/tcl.c | 12 ++++------- 4 files changed, 15 insertions(+), 78 deletions(-) hooks/post-receive -- Main OpenOCD repository |