summaryrefslogtreecommitdiffstats
path: root/devel/ltrace/patches/0001-expr_node_zero-and-expr_self-should-be-stack-allocat.patch
blob: 4b5bfa0b7893c86289a741bc3992864bebae939b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
From 1233b37167097dffa9a78bd7bd0a8117c75fe8ff Mon Sep 17 00:00:00 2001
From: Petr Machata <pmachata@redhat.com>
Date: Sat, 8 Dec 2012 03:13:29 +0100
Subject: [PATCH] expr_node_zero and expr_self should be stack-allocated

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 expr.c | 14 ++++++--------
 zero.c | 14 ++++++--------
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/expr.c b/expr.c
index 32860fd2e2e9..552a53ce63e7 100644
--- a/expr.c
+++ b/expr.c
@@ -21,7 +21,6 @@
 #include <string.h>
 #include <assert.h>
 #include <errno.h>
-#include <error.h>
 #include <stdlib.h>

 #include "expr.h"
@@ -327,12 +326,11 @@ expr_eval_constant(struct expr_node *node, long *valuep)
 struct expr_node *
 expr_self(void)
 {
-	static struct expr_node *node = NULL;
-	if (node == NULL) {
-		node = malloc(sizeof(*node));
-		if (node == NULL)
-			error(1, errno, "malloc expr_self");
-		expr_init_self(node);
+	static struct expr_node *nodep = NULL;
+	if (nodep == NULL) {
+		static struct expr_node node;
+		expr_init_self(&node);
+		nodep = &node;
	}
-	return node;
+	return nodep;
 }
diff --git a/zero.c b/zero.c
index bc119ee7128c..5757943e389a 100644
--- a/zero.c
+++ b/zero.c
@@ -18,7 +18,6 @@
  * 02110-1301 USA
  */

-#include <error.h>
 #include <errno.h>

 #include "zero.h"
@@ -93,13 +92,12 @@ build_zero_w_arg(struct expr_node *expr, int own)
 struct expr_node *
 expr_node_zero(void)
 {
-	static struct expr_node *node = NULL;
-	if (node == NULL) {
-		node = malloc(sizeof(*node));
-		if (node == NULL)
-			error(1, errno, "malloc expr_node_zero");
-		expr_init_cb1(node, &zero1_callback,
+	static struct expr_node *nodep = NULL;
+	if (nodep == NULL) {
+		static struct expr_node node;
+		expr_init_cb1(&node, &zero1_callback,
			      expr_self(), 0, (void *)-1);
+		nodep = &node;
	}
-	return node;
+	return nodep;
 }
--
2.23.0