aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_common_allocation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-13 18:06:23 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-13 18:06:23 +0100
commitca097ea471280b52d48e8818ec12156af78f32b8 (patch)
treec51771ffcc2c8a65aa86260234b3e1c8d1ca22c6 /src/util/test_common_allocation.c
parent733e5b7845d713a54e352909ac1fb30abf2550c4 (diff)
downloadgnunet-ca097ea471280b52d48e8818ec12156af78f32b8.tar.gz
gnunet-ca097ea471280b52d48e8818ec12156af78f32b8.zip
fix theoretical leak in test
Diffstat (limited to 'src/util/test_common_allocation.c')
-rw-r--r--src/util/test_common_allocation.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/src/util/test_common_allocation.c b/src/util/test_common_allocation.c
index 4ef98b629..4d1b6fe7d 100644
--- a/src/util/test_common_allocation.c
+++ b/src/util/test_common_allocation.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2003, 2005, 2006 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2003, 2005, 2006, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -25,6 +25,7 @@
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27 27
28
28static int 29static int
29check () 30check ()
30{ 31{
@@ -95,47 +96,57 @@ check ()
95 if (ptrs[0] != NULL) 96 if (ptrs[0] != NULL)
96 return 9; 97 return 9;
97 98
98 /* GNUNET_new_array_2d tests */ 99 /* GNUNET_new_array_2d tests */
99 a2 = GNUNET_new_array_2d (17, 22, unsigned int); 100 a2 = GNUNET_new_array_2d (17, 22, unsigned int);
100 for (i = 0; i < 17; i++) 101 for (i = 0; i < 17; i++)
101 { 102 {
102 for (j = 0; j < 22; j++) 103 for (j = 0; j < 22; j++)
103 { 104 {
104 if (0 != a2[i][j]) 105 if (0 != a2[i][j])
105 return 10; 106 {
106 a2[i][j] = i * 100 + j; 107 GNUNET_free (a2);
107 } 108 return 10;
108 } 109 }
109 free (a2); 110 a2[i][j] = i * 100 + j;
110 111 }
111 /* GNUNET_new_array_3d tests */ 112 }
112 a3 = GNUNET_new_array_3d (2, 3, 4, char); 113 GNUNET_free (a2);
113 for (i = 0; i < 2; i++)
114 {
115 for (j = 0; j < 3; j++)
116 {
117 for (k = 0; k < 4; k++)
118 {
119 if (0 != a3[i][j][k])
120 return 11;
121 a3[i][j][k] = i * 100 + j * 10 + k;
122 }
123 }
124 }
125 free (a3);
126 114
115 /* GNUNET_new_array_3d tests */
116 a3 = GNUNET_new_array_3d (2, 3, 4, char);
117 for (i = 0; i < 2; i++)
118 {
119 for (j = 0; j < 3; j++)
120 {
121 for (k = 0; k < 4; k++)
122 {
123 if (0 != a3[i][j][k])
124 {
125 GNUNET_free (a3);
126 return 11;
127 }
128 a3[i][j][k] = i * 100 + j * 10 + k;
129 }
130 }
131 }
132 GNUNET_free (a3);
127 return 0; 133 return 0;
128} 134}
129 135
136
130int 137int
131main (int argc, char *argv[]) 138main (int argc, char *argv[])
132{ 139{
133 int ret; 140 int ret;
134 141
135 GNUNET_log_setup ("test-common-allocation", "WARNING", NULL); 142 GNUNET_log_setup ("test-common-allocation",
143 "WARNING",
144 NULL);
136 ret = check (); 145 ret = check ();
137 if (ret != 0) 146 if (ret != 0)
138 FPRINTF (stderr, "ERROR %d.\n", ret); 147 FPRINTF (stderr,
148 "ERROR %d.\n",
149 ret);
139 return ret; 150 return ret;
140} 151}
141 152