@@ -255,10 +255,8 @@ PHP_FUNCTION(jwt_encode)
255
255
jwt -> alg = jwt_str_alg (alg );
256
256
257
257
if (jwt -> alg == JWT_ALG_INVAL ) {
258
- jwt_free (jwt );
259
-
260
258
zend_throw_exception (zend_ce_exception , "Algorithm not supported" , 0 );
261
- RETURN_FALSE ;
259
+ goto encode_done ;
262
260
}
263
261
264
262
/* init */
@@ -288,11 +286,8 @@ PHP_FUNCTION(jwt_encode)
288
286
289
287
/* sign */
290
288
if (jwt_sign (jwt , & sig , & sig_len )) {
291
- efree (sig );
292
- jwt_free (jwt );
293
-
294
289
zend_throw_exception (zend_ce_exception , "Signature error" , 0 );
295
- RETURN_FALSE ;
290
+ goto encode_done ;
296
291
}
297
292
298
293
/* string concatenation */
@@ -305,11 +300,16 @@ PHP_FUNCTION(jwt_encode)
305
300
306
301
smart_str_0 (& segments );
307
302
303
+ encode_done :
308
304
/* free */
309
- efree (sig );
305
+ if (sig )
306
+ efree (sig );
307
+
310
308
jwt_free (jwt );
311
-
312
- RETURN_STR (segments .s );
309
+
310
+ if (segments .s ) {
311
+ RETURN_STR (segments .s );
312
+ }
313
313
}
314
314
315
315
PHP_FUNCTION (jwt_decode )
@@ -365,8 +365,8 @@ PHP_FUNCTION(jwt_decode)
365
365
366
366
if (!json_h ) {
367
367
zend_throw_exception (zend_ce_exception , "Base64 decode error" , 0 );
368
- goto decode_done ;
369
- }
368
+ goto decode_done ;
369
+ }
370
370
371
371
php_json_decode_ex (& zv , ZSTR_VAL (json_h ), ZSTR_LEN (json_h ), PHP_JSON_OBJECT_AS_ARRAY , 512 );
372
372
zend_string_free (json_h );
@@ -433,7 +433,7 @@ PHP_MINFO_FUNCTION(jwt)
433
433
434
434
/* openssl version info */
435
435
php_info_print_table_row (2 , "OpenSSL Library Version" , SSLeay_version (SSLEAY_VERSION ));
436
- php_info_print_table_row (2 , "OpenSSL Header Version" , OPENSSL_VERSION_TEXT );
436
+ php_info_print_table_row (2 , "OpenSSL Header Version" , OPENSSL_VERSION_TEXT );
437
437
438
438
php_info_print_table_end ();
439
439
}
0 commit comments