oj 3.14.2 → 3.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +0 -1
- data/ext/oj/buf.h +2 -2
- data/ext/oj/cache.c +16 -16
- data/ext/oj/cache8.c +7 -7
- data/ext/oj/circarray.c +2 -1
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +2 -2
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +6 -14
- data/ext/oj/custom.c +1 -1
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +16 -16
- data/ext/oj/dump_compat.c +551 -576
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +35 -36
- data/ext/oj/dump_strict.c +2 -4
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +1 -1
- data/ext/oj/fast.c +24 -38
- data/ext/oj/intern.c +38 -42
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +211 -217
- data/ext/oj/mem.h +10 -10
- data/ext/oj/mimic_json.c +18 -24
- data/ext/oj/object.c +5 -5
- data/ext/oj/odd.c +2 -1
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +60 -81
- data/ext/oj/oj.h +53 -54
- data/ext/oj/parse.c +55 -118
- data/ext/oj/parse.h +5 -10
- data/ext/oj/parser.c +7 -8
- data/ext/oj/parser.h +7 -8
- data/ext/oj/rails.c +28 -59
- data/ext/oj/reader.c +5 -9
- data/ext/oj/reader.h +1 -1
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +1 -1
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +4 -4
- data/ext/oj/saj2.c +32 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +18 -67
- data/ext/oj/stream_writer.c +5 -18
- data/ext/oj/strict.c +7 -13
- data/ext/oj/string_writer.c +6 -14
- data/ext/oj/trace.h +27 -16
- data/ext/oj/usual.c +62 -61
- data/ext/oj/usual.h +6 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.h +4 -4
- data/ext/oj/wab.c +7 -9
- data/lib/oj/active_support_helper.rb +0 -1
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +0 -1
- data/lib/oj/json.rb +4 -2
- data/lib/oj/mimic.rb +4 -2
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +0 -1
- data/test/_test_active.rb +0 -1
- data/test/_test_active_mimic.rb +0 -1
- data/test/_test_mimic_rails.rb +0 -1
- data/test/activerecord/result_test.rb +5 -6
- data/test/bar.rb +3 -3
- data/test/files.rb +1 -1
- data/test/foo.rb +5 -48
- data/test/helper.rb +1 -4
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +4 -4
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +43 -32
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +46 -46
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/mem.rb +7 -7
- data/test/perf.rb +2 -2
- data/test/perf_compat.rb +1 -1
- data/test/perf_fast.rb +1 -1
- data/test/perf_file.rb +2 -2
- data/test/perf_object.rb +1 -2
- data/test/perf_once.rb +4 -4
- data/test/perf_parser.rb +1 -2
- data/test/perf_saj.rb +1 -2
- data/test/perf_scp.rb +1 -1
- data/test/perf_simple.rb +3 -3
- data/test/perf_strict.rb +1 -1
- data/test/perf_wab.rb +1 -1
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +2 -3
- data/test/sample_json.rb +0 -1
- data/test/test_compat.rb +11 -9
- data/test/test_custom.rb +5 -9
- data/test/test_debian.rb +1 -1
- data/test/test_fast.rb +10 -20
- data/test/test_file.rb +8 -8
- data/test/test_integer_range.rb +2 -2
- data/test/test_null.rb +5 -3
- data/test/test_object.rb +6 -5
- data/test/test_parser_saj.rb +23 -21
- data/test/test_parser_usual.rb +3 -3
- data/test/test_saj.rb +2 -0
- data/test/test_scp.rb +6 -6
- data/test/test_strict.rb +6 -4
- data/test/test_various.rb +21 -24
- data/test/test_wab.rb +6 -5
- data/test/test_writer.rb +1 -1
- metadata +17 -26
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
data/ext/oj/mem.c
CHANGED
@@ -1,259 +1,253 @@
|
|
1
1
|
// Copyright (c) 2018, Peter Ohler, All rights reserved.
|
2
2
|
|
3
|
+
#include "mem.h"
|
4
|
+
|
3
5
|
#include <pthread.h>
|
6
|
+
#include <ruby.h>
|
4
7
|
#include <stdbool.h>
|
5
8
|
#include <stdint.h>
|
6
9
|
#include <stdio.h>
|
7
10
|
#include <stdlib.h>
|
8
11
|
#include <string.h>
|
9
12
|
|
10
|
-
#include <ruby.h>
|
11
|
-
|
12
|
-
#include "mem.h"
|
13
|
-
|
14
13
|
typedef struct _rec {
|
15
|
-
struct _rec
|
16
|
-
const void
|
17
|
-
size_t
|
18
|
-
const char
|
19
|
-
int
|
20
|
-
bool
|
14
|
+
struct _rec *next;
|
15
|
+
const void *ptr;
|
16
|
+
size_t size;
|
17
|
+
const char *file;
|
18
|
+
int line;
|
19
|
+
bool ruby;
|
21
20
|
} *Rec;
|
22
21
|
|
23
22
|
typedef struct _rep {
|
24
|
-
struct _rep
|
25
|
-
size_t
|
26
|
-
const char
|
27
|
-
int
|
28
|
-
int
|
23
|
+
struct _rep *next;
|
24
|
+
size_t size;
|
25
|
+
const char *file;
|
26
|
+
int line;
|
27
|
+
int cnt;
|
29
28
|
} *Rep;
|
30
29
|
|
31
30
|
#ifdef MEM_DEBUG
|
32
31
|
|
33
|
-
static pthread_mutex_t
|
34
|
-
static Rec
|
35
|
-
static const char
|
32
|
+
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
33
|
+
static Rec recs = NULL;
|
34
|
+
static const char mem_pad[] = "--- This is a memory pad and should not change until being freed. ---";
|
36
35
|
|
37
|
-
void*
|
38
|
-
|
39
|
-
void *ptr = malloc(size + sizeof(mem_pad));
|
36
|
+
void *oj_malloc(size_t size, const char *file, int line) {
|
37
|
+
void *ptr = malloc(size + sizeof(mem_pad));
|
40
38
|
|
41
39
|
if (NULL != ptr) {
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
Rec r = (Rec)malloc(sizeof(struct _rec));
|
41
|
+
|
42
|
+
if (NULL != r) {
|
43
|
+
strcpy(((char *)ptr) + size, mem_pad);
|
44
|
+
r->ptr = ptr;
|
45
|
+
r->size = size;
|
46
|
+
r->file = file;
|
47
|
+
r->line = line;
|
50
48
|
r->ruby = false;
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
49
|
+
pthread_mutex_lock(&lock);
|
50
|
+
r->next = recs;
|
51
|
+
recs = r;
|
52
|
+
pthread_mutex_unlock(&lock);
|
53
|
+
} else {
|
54
|
+
free(ptr);
|
55
|
+
ptr = NULL;
|
56
|
+
}
|
59
57
|
}
|
60
58
|
return ptr;
|
61
59
|
}
|
62
60
|
|
63
|
-
void*
|
64
|
-
|
65
|
-
|
66
|
-
Rec r;
|
61
|
+
void *oj_realloc(void *orig, size_t size, const char *file, int line) {
|
62
|
+
void *ptr = realloc(orig, size + sizeof(mem_pad));
|
63
|
+
Rec r;
|
67
64
|
|
68
65
|
if (NULL != ptr) {
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
66
|
+
strcpy(((char *)ptr) + size, mem_pad);
|
67
|
+
pthread_mutex_lock(&lock);
|
68
|
+
for (r = recs; NULL != r; r = r->next) {
|
69
|
+
if (orig == r->ptr) {
|
70
|
+
r->ptr = ptr;
|
71
|
+
r->size = size;
|
72
|
+
r->file = file;
|
73
|
+
r->line = line;
|
77
74
|
r->ruby = false;
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
pthread_mutex_unlock(&lock);
|
79
|
+
if (NULL == r) {
|
80
|
+
printf("Realloc at %s:%d (%p) not allocated.\n", file, line, orig);
|
81
|
+
}
|
85
82
|
}
|
86
83
|
return ptr;
|
87
84
|
}
|
88
85
|
|
89
|
-
void*
|
90
|
-
|
91
|
-
void *ptr;
|
86
|
+
void *oj_calloc(size_t count, size_t size, const char *file, int line) {
|
87
|
+
void *ptr;
|
92
88
|
|
93
89
|
size *= count;
|
94
90
|
if (NULL != (ptr = malloc(size + sizeof(mem_pad)))) {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
91
|
+
Rec r = (Rec)malloc(sizeof(struct _rec));
|
92
|
+
|
93
|
+
if (NULL != r) {
|
94
|
+
memset(ptr, 0, size);
|
95
|
+
strcpy(((char *)ptr) + size, mem_pad);
|
96
|
+
r->ptr = ptr;
|
97
|
+
r->size = size;
|
98
|
+
r->file = file;
|
99
|
+
r->line = line;
|
104
100
|
r->ruby = false;
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
101
|
+
pthread_mutex_lock(&lock);
|
102
|
+
r->next = recs;
|
103
|
+
recs = r;
|
104
|
+
pthread_mutex_unlock(&lock);
|
105
|
+
} else {
|
106
|
+
free(ptr);
|
107
|
+
ptr = NULL;
|
108
|
+
}
|
113
109
|
}
|
114
110
|
return ptr;
|
115
111
|
}
|
116
112
|
|
117
|
-
void*
|
118
|
-
|
119
|
-
void *ptr = ruby_xmalloc(size + sizeof(mem_pad));
|
113
|
+
void *oj_r_alloc(size_t size, const char *file, int line) {
|
114
|
+
void *ptr = ruby_xmalloc(size + sizeof(mem_pad));
|
120
115
|
|
121
116
|
if (NULL != ptr) {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
117
|
+
Rec r = (Rec)malloc(sizeof(struct _rec));
|
118
|
+
|
119
|
+
if (NULL != r) {
|
120
|
+
strcpy(((char *)ptr) + size, mem_pad);
|
121
|
+
r->ptr = ptr;
|
122
|
+
r->size = size;
|
123
|
+
r->file = file;
|
124
|
+
r->line = line;
|
130
125
|
r->ruby = true;
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
126
|
+
pthread_mutex_lock(&lock);
|
127
|
+
r->next = recs;
|
128
|
+
recs = r;
|
129
|
+
pthread_mutex_unlock(&lock);
|
130
|
+
} else {
|
131
|
+
free(ptr);
|
132
|
+
ptr = NULL;
|
133
|
+
}
|
139
134
|
}
|
140
135
|
return ptr;
|
141
136
|
}
|
142
137
|
|
143
|
-
void*
|
144
|
-
|
145
|
-
|
146
|
-
Rec r;
|
138
|
+
void *oj_r_realloc(void *orig, size_t size, const char *file, int line) {
|
139
|
+
void *ptr = ruby_xrealloc2(orig, 1, size + sizeof(mem_pad));
|
140
|
+
Rec r;
|
147
141
|
|
148
142
|
if (NULL != ptr) {
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
143
|
+
strcpy(((char *)ptr) + size, mem_pad);
|
144
|
+
pthread_mutex_lock(&lock);
|
145
|
+
for (r = recs; NULL != r; r = r->next) {
|
146
|
+
if (orig == r->ptr) {
|
147
|
+
r->ptr = ptr;
|
148
|
+
r->size = size;
|
149
|
+
r->file = file;
|
150
|
+
r->line = line;
|
157
151
|
r->ruby = true;
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
152
|
+
break;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
pthread_mutex_unlock(&lock);
|
156
|
+
if (NULL == r) {
|
157
|
+
printf("Realloc at %s:%d (%p) not allocated.\n", file, line, orig);
|
158
|
+
}
|
165
159
|
}
|
166
160
|
return ptr;
|
167
161
|
}
|
168
162
|
|
169
|
-
|
170
|
-
void
|
171
|
-
oj_freed(void *ptr, const char *file, int line, bool ruby) {
|
163
|
+
void oj_freed(void *ptr, const char *file, int line, bool ruby) {
|
172
164
|
if (NULL != ptr) {
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
165
|
+
Rec r = NULL;
|
166
|
+
Rec prev = NULL;
|
167
|
+
|
168
|
+
pthread_mutex_lock(&lock);
|
169
|
+
for (r = recs; NULL != r; r = r->next) {
|
170
|
+
if (ptr == r->ptr) {
|
171
|
+
if (NULL == prev) {
|
172
|
+
recs = r->next;
|
173
|
+
} else {
|
174
|
+
prev->next = r->next;
|
175
|
+
}
|
176
|
+
break;
|
177
|
+
}
|
178
|
+
prev = r;
|
179
|
+
}
|
180
|
+
pthread_mutex_unlock(&lock);
|
181
|
+
if (NULL == r) {
|
182
|
+
printf("Free at %s:%d (%p) not allocated or already freed.\n", file, line, ptr);
|
183
|
+
} else {
|
184
|
+
char *pad = (char *)r->ptr + r->size;
|
193
185
|
|
194
186
|
if (r->ruby != ruby) {
|
195
187
|
if (r->ruby) {
|
196
|
-
printf("Memory at %s:%d (%p) allocated with Ruby allocator and freed with stdlib free.\n",
|
188
|
+
printf("Memory at %s:%d (%p) allocated with Ruby allocator and freed with stdlib free.\n",
|
189
|
+
file,
|
190
|
+
line,
|
191
|
+
ptr);
|
197
192
|
} else {
|
198
|
-
printf("Memory at %s:%d (%p) allocated with stdlib allocator and freed with Ruby free.\n",
|
193
|
+
printf("Memory at %s:%d (%p) allocated with stdlib allocator and freed with Ruby free.\n",
|
194
|
+
file,
|
195
|
+
line,
|
196
|
+
ptr);
|
197
|
+
}
|
198
|
+
}
|
199
|
+
if (0 != strcmp(mem_pad, pad)) {
|
200
|
+
uint8_t *p;
|
201
|
+
uint8_t *end = (uint8_t *)pad + sizeof(mem_pad);
|
202
|
+
|
203
|
+
printf("Memory at %s:%d (%p) write outside allocated.\n", file, line, ptr);
|
204
|
+
for (p = (uint8_t *)pad; p < end; p++) {
|
205
|
+
if (0x20 < *p && *p < 0x7f) {
|
206
|
+
printf("%c ", *p);
|
207
|
+
} else {
|
208
|
+
printf("%02x ", *(uint8_t *)p);
|
209
|
+
}
|
199
210
|
}
|
211
|
+
printf("\n");
|
200
212
|
}
|
201
|
-
|
202
|
-
|
203
|
-
uint8_t *end = (uint8_t*)pad + sizeof(mem_pad);
|
204
|
-
|
205
|
-
printf("Memory at %s:%d (%p) write outside allocated.\n", file, line, ptr);
|
206
|
-
for (p = (uint8_t*)pad; p < end; p++) {
|
207
|
-
if (0x20 < *p && *p < 0x7f) {
|
208
|
-
printf("%c ", *p);
|
209
|
-
} else {
|
210
|
-
printf("%02x ", *(uint8_t*)p);
|
211
|
-
}
|
212
|
-
}
|
213
|
-
printf("\n");
|
214
|
-
}
|
215
|
-
free(r);
|
216
|
-
}
|
213
|
+
free(r);
|
214
|
+
}
|
217
215
|
}
|
218
216
|
}
|
219
217
|
|
220
|
-
void
|
221
|
-
oj_r_free(void *ptr, const char *file, int line) {
|
218
|
+
void oj_r_free(void *ptr, const char *file, int line) {
|
222
219
|
oj_freed(ptr, file, line, true);
|
223
220
|
xfree(ptr);
|
224
221
|
}
|
225
222
|
|
226
|
-
|
227
|
-
void
|
228
|
-
oj_free(void *ptr, const char *file, int line) {
|
223
|
+
void oj_free(void *ptr, const char *file, int line) {
|
229
224
|
oj_freed(ptr, file, line, false);
|
230
225
|
free(ptr);
|
231
226
|
}
|
232
227
|
|
233
|
-
char*
|
234
|
-
|
235
|
-
|
236
|
-
char *ptr = (char*)malloc(size + sizeof(mem_pad));
|
228
|
+
char *oj_mem_strdup(const char *str, const char *file, int line) {
|
229
|
+
size_t size = strlen(str) + 1;
|
230
|
+
char *ptr = (char *)malloc(size + sizeof(mem_pad));
|
237
231
|
|
238
232
|
if (NULL != ptr) {
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
233
|
+
Rec r = (Rec)malloc(sizeof(struct _rec));
|
234
|
+
|
235
|
+
if (NULL != r) {
|
236
|
+
strcpy(ptr, str);
|
237
|
+
strcpy(((char *)ptr) + size, mem_pad);
|
238
|
+
r->ptr = (void *)ptr;
|
239
|
+
r->size = size;
|
240
|
+
r->file = file;
|
241
|
+
r->line = line;
|
248
242
|
r->ruby = false;
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
243
|
+
pthread_mutex_lock(&lock);
|
244
|
+
r->next = recs;
|
245
|
+
recs = r;
|
246
|
+
pthread_mutex_unlock(&lock);
|
247
|
+
} else {
|
248
|
+
free(ptr);
|
249
|
+
ptr = NULL;
|
250
|
+
}
|
257
251
|
}
|
258
252
|
return ptr;
|
259
253
|
}
|
@@ -262,52 +256,53 @@ oj_mem_strdup(const char *str, const char *file, int line) {
|
|
262
256
|
|
263
257
|
#ifdef MEM_DEBUG
|
264
258
|
|
265
|
-
static Rep
|
266
|
-
|
267
|
-
Rep rp = reps;
|
259
|
+
static Rep update_reps(Rep reps, Rec r) {
|
260
|
+
Rep rp = reps;
|
268
261
|
|
269
262
|
for (; NULL != rp; rp = rp->next) {
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
263
|
+
if (rp->line == r->line && (rp->file == r->file || 0 == strcmp(rp->file, r->file))) {
|
264
|
+
rp->size += r->size;
|
265
|
+
rp->cnt++;
|
266
|
+
break;
|
267
|
+
}
|
275
268
|
}
|
276
|
-
if (NULL == rp &&
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
reps = rp;
|
269
|
+
if (NULL == rp && NULL != (rp = (Rep)malloc(sizeof(struct _rep)))) {
|
270
|
+
rp->size = r->size;
|
271
|
+
rp->file = r->file;
|
272
|
+
rp->line = r->line;
|
273
|
+
rp->cnt = 1;
|
274
|
+
rp->next = reps;
|
275
|
+
reps = rp;
|
284
276
|
}
|
285
277
|
return reps;
|
286
278
|
}
|
287
279
|
|
288
|
-
static void
|
289
|
-
print_stats() {
|
280
|
+
static void print_stats() {
|
290
281
|
printf("\n--- Memory Usage Report --------------------------------------------------------\n");
|
291
282
|
pthread_mutex_lock(&lock);
|
292
283
|
|
293
284
|
if (NULL == recs) {
|
294
|
-
|
285
|
+
printf("No memory leaks\n");
|
295
286
|
} else {
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
287
|
+
Rep reps = NULL;
|
288
|
+
Rep rp;
|
289
|
+
Rec r;
|
290
|
+
size_t leaked = 0;
|
291
|
+
|
292
|
+
for (r = recs; NULL != r; r = r->next) {
|
293
|
+
reps = update_reps(reps, r);
|
294
|
+
}
|
295
|
+
while (NULL != (rp = reps)) {
|
296
|
+
reps = rp->next;
|
297
|
+
printf("%16s:%3d %8lu bytes over %d occurances allocated and not freed.\n",
|
298
|
+
rp->file,
|
299
|
+
rp->line,
|
300
|
+
rp->size,
|
301
|
+
rp->cnt);
|
302
|
+
leaked += rp->size;
|
303
|
+
free(rp);
|
304
|
+
}
|
305
|
+
printf("%lu bytes leaked\n", leaked);
|
311
306
|
}
|
312
307
|
pthread_mutex_unlock(&lock);
|
313
308
|
printf("--------------------------------------------------------------------------------\n");
|
@@ -315,8 +310,7 @@ print_stats() {
|
|
315
310
|
|
316
311
|
#endif
|
317
312
|
|
318
|
-
void
|
319
|
-
oj_mem_report() {
|
313
|
+
void oj_mem_report(void) {
|
320
314
|
#ifdef MEM_DEBUG
|
321
315
|
rb_gc();
|
322
316
|
print_stats();
|
data/ext/oj/mem.h
CHANGED
@@ -16,21 +16,21 @@
|
|
16
16
|
|
17
17
|
#define OJ_R_ALLOC(type) oj_r_alloc(sizeof(type), __FILE__, __LINE__)
|
18
18
|
#define OJ_R_ALLOC_N(type, n) (type *)oj_r_alloc(sizeof(type) * (n), __FILE__, __LINE__)
|
19
|
-
#define OJ_R_REALLOC_N(ptr, type, n) ((ptr) = (type*)oj_r_realloc(ptr, (sizeof(type) * (n)), __FILE__, __LINE__))
|
19
|
+
#define OJ_R_REALLOC_N(ptr, type, n) ((ptr) = (type *)oj_r_realloc(ptr, (sizeof(type) * (n)), __FILE__, __LINE__))
|
20
20
|
#define OJ_R_FREE(ptr) oj_r_free(ptr, __FILE__, __LINE__)
|
21
21
|
|
22
22
|
#define OJ_STRDUP(str) oj_mem_strdup(str, __FILE__, __LINE__)
|
23
23
|
|
24
|
-
extern void*
|
25
|
-
extern void*
|
26
|
-
extern void*
|
27
|
-
extern void
|
24
|
+
extern void *oj_malloc(size_t size, const char *file, int line);
|
25
|
+
extern void *oj_realloc(void *ptr, size_t size, const char *file, int line);
|
26
|
+
extern void *oj_calloc(size_t count, size_t size, const char *file, int line);
|
27
|
+
extern void oj_free(void *ptr, const char *file, int line);
|
28
28
|
|
29
|
-
extern void*
|
30
|
-
extern void*
|
31
|
-
extern void
|
29
|
+
extern void *oj_r_alloc(size_t size, const char *file, int line);
|
30
|
+
extern void *oj_r_realloc(void *ptr, size_t size, const char *file, int line);
|
31
|
+
extern void oj_r_free(void *ptr, const char *file, int line);
|
32
32
|
|
33
|
-
extern char*
|
33
|
+
extern char *oj_mem_strdup(const char *str, const char *file, int line);
|
34
34
|
|
35
35
|
#else
|
36
36
|
|
@@ -48,6 +48,6 @@ extern char* oj_mem_strdup(const char *str, const char *file, int line);
|
|
48
48
|
|
49
49
|
#endif
|
50
50
|
|
51
|
-
extern void
|
51
|
+
extern void oj_mem_report();
|
52
52
|
|
53
53
|
#endif /* OJ_MEM_H */
|