lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20131129103707.GB1231@krava.brq.redhat.com>
Date:	Fri, 29 Nov 2013 11:37:07 +0100
From:	Jiri Olsa <jolsa@...hat.com>
To:	Namhyung Kim <namhyung@...nel.org>
Cc:	linux-kernel@...r.kernel.org,
	Corey Ashford <cjashfor@...ux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Ingo Molnar <mingo@...e.hu>, Paul Mackerras <paulus@...ba.org>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Arnaldo Carvalho de Melo <acme@...stprotocols.net>,
	Steven Rostedt <rostedt@...dmis.org>,
	David Ahern <dsahern@...il.com>
Subject: [PATCHv3 20/29] tools lib traceevent: Remove malloc_or_die from
 plugin_function.c

On Fri, Nov 29, 2013 at 03:41:10PM +0900, Namhyung Kim wrote:
> Hi Jiri,
> 
> On Thu, 28 Nov 2013 12:33:19 +0100, Jiri Olsa wrote:
> > Removing malloc_or_die calls from plugin_function.c,
> > replacing them with standard malloc and error path.
> >
> > Suggested-by: Namhyung Kim <namhyung@...nel.org>
> > Signed-off-by: Jiri Olsa <jolsa@...hat.com>
> > Cc: Corey Ashford <cjashfor@...ux.vnet.ibm.com>
> > Cc: Frederic Weisbecker <fweisbec@...il.com>
> > Cc: Ingo Molnar <mingo@...e.hu>
> > Cc: Namhyung Kim <namhyung@...nel.org>
> > Cc: Paul Mackerras <paulus@...ba.org>
> > Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
> > Cc: Arnaldo Carvalho de Melo <acme@...stprotocols.net>
> > Cc: Steven Rostedt <rostedt@...dmis.org>
> > Cc: David Ahern <dsahern@...il.com>
> > ---
> >  tools/lib/traceevent/plugin_function.c | 15 +++++++++++++--
> >  1 file changed, 13 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c
> > index 87acf9c..328d17d 100644
> > --- a/tools/lib/traceevent/plugin_function.c
> > +++ b/tools/lib/traceevent/plugin_function.c
> > @@ -44,10 +44,16 @@ static void add_child(struct func_stack *stack, const char *child, int pos)
> >  		free(stack->stack[pos]);
> >  	else {
> >  		if (!stack->stack)
> > -			stack->stack = malloc_or_die(sizeof(char *) * STK_BLK);
> > +			stack->stack = malloc(sizeof(char *) * STK_BLK);
> >  		else
> >  			stack->stack = realloc(stack->stack, sizeof(char *) *
> >  					       (stack->size + STK_BLK));
> 
> I think single realloc() can handle both cases.  And this code has a
> problem that it overwrites stack->stack to NULL in case of error so that
> we cannot point original region anymore.  You'd better to use a temp
> variable IMHO.

right you are, please check v3 attached..

thanks,
jirka


---
Removing malloc_or_die calls from plugin_function.c,
replacing them and factoring the code with standard
realloc and error path.

Suggested-by: Namhyung Kim <namhyung@...nel.org>
Signed-off-by: Jiri Olsa <jolsa@...hat.com>
Cc: Corey Ashford <cjashfor@...ux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Ingo Molnar <mingo@...e.hu>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: David Ahern <dsahern@...il.com>
---
 tools/lib/traceevent/plugin_function.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c
index 87acf9c..b43cade 100644
--- a/tools/lib/traceevent/plugin_function.c
+++ b/tools/lib/traceevent/plugin_function.c
@@ -43,11 +43,17 @@ static void add_child(struct func_stack *stack, const char *child, int pos)
 	if (pos < stack->size)
 		free(stack->stack[pos]);
 	else {
-		if (!stack->stack)
-			stack->stack = malloc_or_die(sizeof(char *) * STK_BLK);
-		else
-			stack->stack = realloc(stack->stack, sizeof(char *) *
-					       (stack->size + STK_BLK));
+		char **ptr;
+
+		ptr = realloc(stack->stack, sizeof(char *) *
+			      (stack->size + STK_BLK));
+		if (!ptr) {
+			warning("could not allocate plugin memory\n");
+			return;
+		}
+
+		stack->stack = ptr;
+
 		for (i = stack->size; i < stack->size + STK_BLK; i++)
 			stack->stack[i] = NULL;
 		stack->size += STK_BLK;
@@ -64,10 +70,11 @@ static int add_and_get_index(const char *parent, const char *child, int cpu)
 		return 0;
 
 	if (cpu > cpus) {
-		if (fstack)
-			fstack = realloc(fstack, sizeof(*fstack) * (cpu + 1));
-		else
-			fstack = malloc_or_die(sizeof(*fstack) * (cpu + 1));
+		fstack = realloc(fstack, sizeof(*fstack) * (cpu + 1));
+		if (!fstack) {
+			warning("could not allocate plugin memory\n");
+			return 0;
+		}
 
 		/* Account for holes in the cpu count */
 		for (i = cpus + 1; i <= cpu; i++)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ