Bug Summary

File:pool.c
Location:line 236, column 9
Description:Null pointer passed as an argument to a 'nonnull' parameter

Annotated Source Code

1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 *
19 * @author Mladen Turk
20 * @version $Id: pool.c 1442587 2013-02-05 13:49:48Z rjung $
21 */
22
23#include "tcn.h"
24
25extern apr_pool_t *tcn_global_pool;
26
27static apr_status_t generic_pool_cleanup(void *data)
28{
29 apr_status_t rv = APR_SUCCESS0;
30 tcn_callback_t *cb = (tcn_callback_t *)data;
31
32 if (data) {
33 JNIEnv *env;
34 tcn_get_java_env(&env);
35 if (!TCN_IS_NULL(env, cb->obj)((*(env))->IsSameObject((env), (cb->obj), ((void*)0)) ==
1)
) {
36 rv = (*(env))->CallIntMethod(env, cb->obj, cb->mid[0],
37 NULL((void*)0));
38 TCN_UNLOAD_CLASS(env, cb->obj)(*(env))->DeleteGlobalRef((env), (cb->obj));
39 }
40 free(cb);
41 }
42 return rv;
43}
44
45TCN_IMPLEMENT_CALL(jlong, Pool, create)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_Pool_create(TCN_STDARGSJNIEnv *e, jobject o, jlong parent)
46{
47 apr_pool_t *p = J2P(parent, apr_pool_t *)((apr_pool_t *)((long)((jlong)parent)));
48 apr_pool_t *n;
49
50 UNREFERENCED(o)(o) = (o);
51 /* Make sure our global pool is accessor for all pools */
52 if (p == NULL((void*)0))
53 p = tcn_global_pool;
54 TCN_THROW_IF_ERR(apr_pool_create(&n, p), n)if (1) { apr_status_t R = (apr_pool_create_ex(&n, p, ((void
*)0), ((void*)0))); if (R != 0) { tcn_ThrowAPRException(e, R)
; (n) = 0; goto cleanup; } } else (void)(0)
;
55cleanup:
56 return P2J(n)((jlong)((long)(n)));
57}
58
59TCN_IMPLEMENT_CALL(void, Pool, clear)__attribute__((visibility("default"))) void Java_org_apache_tomcat_jni_Pool_clear(TCN_STDARGSJNIEnv *e, jobject o, jlong pool)
60{
61 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
62 UNREFERENCED_STDARGSe = e; o = o;
63 TCN_ASSERT(pool != 0)(void)0;
64 apr_pool_clear(p);
65}
66
67TCN_IMPLEMENT_CALL(void, Pool, destroy)__attribute__((visibility("default"))) void Java_org_apache_tomcat_jni_Pool_destroy(TCN_STDARGSJNIEnv *e, jobject o, jlong pool)
68{
69 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
70 UNREFERENCED_STDARGSe = e; o = o;
71 TCN_ASSERT(pool != 0)(void)0;
72 apr_pool_destroy(p);
73}
74
75TCN_IMPLEMENT_CALL(jlong, Pool, parentGet)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_Pool_parentGet(TCN_STDARGSJNIEnv *e, jobject o, jlong pool)
76{
77 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
78 UNREFERENCED_STDARGSe = e; o = o;
79 TCN_ASSERT(pool != 0)(void)0;
80 return P2J(apr_pool_parent_get(p))((jlong)((long)(apr_pool_parent_get(p))));
81}
82
83TCN_IMPLEMENT_CALL(jboolean, Pool, isAncestor)__attribute__((visibility("default"))) jboolean Java_org_apache_tomcat_jni_Pool_isAncestor(TCN_STDARGSJNIEnv *e, jobject o, jlong a, jlong b)
84{
85 apr_pool_t *pa = J2P(a, apr_pool_t *)((apr_pool_t *)((long)((jlong)a)));
86 apr_pool_t *pb = J2P(b, apr_pool_t *)((apr_pool_t *)((long)((jlong)b)));
87 UNREFERENCED_STDARGSe = e; o = o;
88 return apr_pool_is_ancestor(pa, pb) ? JNI_TRUE1 : JNI_FALSE0;
89}
90
91TCN_IMPLEMENT_CALL(jlong, Pool, palloc)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_Pool_palloc(TCN_STDARGSJNIEnv *e, jobject o, jlong pool, jint size)
92{
93 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
94 UNREFERENCED_STDARGSe = e; o = o;
95 return P2J(apr_palloc(p, (apr_size_t)size))((jlong)((long)(apr_palloc(p, (apr_size_t)size))));
96}
97
98TCN_IMPLEMENT_CALL(jlong, Pool, pcalloc)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_Pool_pcalloc(TCN_STDARGSJNIEnv *e, jobject o, jlong pool, jint size)
99{
100 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
101 UNREFERENCED_STDARGSe = e; o = o;
102 return P2J(apr_pcalloc(p, (apr_size_t)size))((jlong)((long)(memset(apr_palloc(p, (apr_size_t)size), 0, (apr_size_t
)size))))
;
103}
104
105TCN_IMPLEMENT_CALL(jlong, Pool, cleanupRegister)__attribute__((visibility("default"))) jlong Java_org_apache_tomcat_jni_Pool_cleanupRegister(TCN_STDARGSJNIEnv *e, jobject o, jlong pool,
106 jobject obj)
107{
108 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
109 tcn_callback_t *cb = (tcn_callback_t *)malloc(sizeof(tcn_callback_t));
110 jclass cls;
111
112 UNREFERENCED(o)(o) = (o);
113
114 if (cb == NULL((void*)0)) {
115 TCN_THROW_OS_ERROR(e)tcn_ThrowAPRException((e), ((*__errno_location ())));
116 return 0;
117 }
118 cls = (*e)->GetObjectClass(e, obj);
119 cb->obj = (*e)->NewGlobalRef(e, obj);
120 cb->mid[0] = (*e)->GetMethodID(e, cls, "callback", "()I");
121
122 apr_pool_cleanup_register(p, (const void *)cb,
123 generic_pool_cleanup,
124 apr_pool_cleanup_null);
125
126 return P2J(cb)((jlong)((long)(cb)));
127}
128
129TCN_IMPLEMENT_CALL(void, Pool, cleanupKill)__attribute__((visibility("default"))) void Java_org_apache_tomcat_jni_Pool_cleanupKill(TCN_STDARGSJNIEnv *e, jobject o, jlong pool,
130 jlong data)
131{
132 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
133 tcn_callback_t *cb = J2P(data, tcn_callback_t *)((tcn_callback_t *)((long)((jlong)data)));
134
135 UNREFERENCED(o)(o) = (o);
136 TCN_ASSERT(pool != 0)(void)0;
137 apr_pool_cleanup_kill(p, cb, generic_pool_cleanup);
138 (*e)->DeleteGlobalRef(e, cb->obj);
139 free(cb);
140}
141
142TCN_IMPLEMENT_CALL(jobject, Pool, alloc)__attribute__((visibility("default"))) jobject Java_org_apache_tomcat_jni_Pool_alloc(TCN_STDARGSJNIEnv *e, jobject o, jlong pool,
143 jint size)
144{
145 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
146 apr_size_t sz = (apr_size_t)size;
147 void *mem;
148
149 UNREFERENCED(o)(o) = (o);
150 TCN_ASSERT(pool != 0)(void)0;
151
152 if ((mem = apr_palloc(p, sz)) != NULL((void*)0))
153 return (*e)->NewDirectByteBuffer(e, mem, (jlong)sz);
154 else
155 return NULL((void*)0);
156}
157
158TCN_IMPLEMENT_CALL(jobject, Pool, calloc)__attribute__((visibility("default"))) jobject Java_org_apache_tomcat_jni_Pool_calloc(TCN_STDARGSJNIEnv *e, jobject o, jlong pool,
159 jint size)
160{
161 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
162 apr_size_t sz = (apr_size_t)size;
163 void *mem;
164
165 UNREFERENCED(o)(o) = (o);
166 TCN_ASSERT(pool != 0)(void)0;
167
168 if ((mem = apr_pcalloc(p, sz)memset(apr_palloc(p, sz), 0, sz)) != NULL((void*)0))
169 return (*e)->NewDirectByteBuffer(e, mem, (jlong)sz);
170 else
171 return NULL((void*)0);
172}
173
174static apr_status_t generic_pool_data_cleanup(void *data)
175{
176 apr_status_t rv = APR_SUCCESS0;
177 tcn_callback_t *cb = (tcn_callback_t *)data;
178
179 if (data) {
180 JNIEnv *env;
181 tcn_get_java_env(&env);
182
183 if (!TCN_IS_NULL(env, cb->obj)((*(env))->IsSameObject((env), (cb->obj), ((void*)0)) ==
1)
) {
184 TCN_UNLOAD_CLASS(env, cb->obj)(*(env))->DeleteGlobalRef((env), (cb->obj));
185 }
186 free(cb);
187 }
188 return rv;
189}
190
191TCN_IMPLEMENT_CALL(jint, Pool, dataSet)__attribute__((visibility("default"))) jint Java_org_apache_tomcat_jni_Pool_dataSet(TCN_STDARGSJNIEnv *e, jobject o, jlong pool,
192 jstring key, jobject data)
193{
194 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
195 apr_status_t rv = APR_SUCCESS0;
196 void *old = NULL((void*)0);
197 TCN_ALLOC_CSTRING(key)const char *ckey = key ? (const char *)((*e)->GetStringUTFChars
(e, key, 0)) : ((void*)0)
;
198
199 UNREFERENCED(o)(o) = (o);
200 TCN_ASSERT(pool != 0)(void)0;
201
202 if (apr_pool_userdata_get(&old, J2S(key)ckey, p) == APR_SUCCESS0) {
203 if (old)
204 apr_pool_cleanup_run(p, old, generic_pool_data_cleanup);
205 }
206 if (data) {
207 JNIEnv *e;
208 tcn_callback_t *cb = (tcn_callback_t *)malloc(sizeof(tcn_callback_t));
209 tcn_get_java_env(&e);
210 cb->obj = (*e)->NewGlobalRef(e, data);
211 if ((rv = apr_pool_userdata_set(cb, J2S(key)ckey, generic_pool_data_cleanup,
212 p)) != APR_SUCCESS0) {
213 (*e)->DeleteGlobalRef(e, cb->obj);
214 free(cb);
215 }
216 }
217 else {
218 /* Clear the exiting user data */
219 rv = apr_pool_userdata_set(NULL((void*)0), J2S(key)ckey, NULL((void*)0), p);
220 }
221 TCN_FREE_CSTRING(key)if (ckey) (*e)->ReleaseStringUTFChars(e, key, ckey);
222 return rv;
223}
224
225TCN_IMPLEMENT_CALL(jobject, Pool, dataGet)__attribute__((visibility("default"))) jobject Java_org_apache_tomcat_jni_Pool_dataGet(TCN_STDARGSJNIEnv *e, jobject o, jlong pool,
226 jstring key)
227{
228 apr_pool_t *p = J2P(pool, apr_pool_t *)((apr_pool_t *)((long)((jlong)pool)));
229 void *old = NULL((void*)0);
230 TCN_ALLOC_CSTRING(key)const char *ckey = key ? (const char *)((*e)->GetStringUTFChars
(e, key, 0)) : ((void*)0)
;
1
Within the expansion of the macro 'TCN_ALLOC_CSTRING':
a
Assuming 'key' is null
b
'ckey' initialized to a null pointer value
231 jobject rv = NULL((void*)0);
232
233 UNREFERENCED(o)(o) = (o);
234 TCN_ASSERT(pool != 0)(void)0;
235
236 if (apr_pool_userdata_get(&old, J2S(key)ckey, p) == APR_SUCCESS0) {
2
Null pointer passed as an argument to a 'nonnull' parameter
237 if (old) {
238 tcn_callback_t *cb = (tcn_callback_t *)old;
239 rv = cb->obj;
240 }
241 }
242 TCN_FREE_CSTRING(key)if (ckey) (*e)->ReleaseStringUTFChars(e, key, ckey);
243 return rv;
244}
245
246TCN_IMPLEMENT_CALL(void, Pool, cleanupForExec)__attribute__((visibility("default"))) void Java_org_apache_tomcat_jni_Pool_cleanupForExec(TCN_STDARGSJNIEnv *e, jobject o)
247{
248 UNREFERENCED_STDARGSe = e; o = o;
249 apr_pool_cleanup_for_exec();
250}