@@ -255,10 +255,8 @@ PHP_FUNCTION(jwt_encode)
255255 jwt -> alg = jwt_str_alg (alg );
256256
257257 if (jwt -> alg == JWT_ALG_INVAL ) {
258- jwt_free (jwt );
259-
260258 zend_throw_exception (zend_ce_exception , "Algorithm not supported" , 0 );
261- RETURN_FALSE ;
259+ goto encode_done ;
262260 }
263261
264262 /* init */
@@ -288,11 +286,8 @@ PHP_FUNCTION(jwt_encode)
288286
289287 /* sign */
290288 if (jwt_sign (jwt , & sig , & sig_len )) {
291- efree (sig );
292- jwt_free (jwt );
293-
294289 zend_throw_exception (zend_ce_exception , "Signature error" , 0 );
295- RETURN_FALSE ;
290+ goto encode_done ;
296291 }
297292
298293 /* string concatenation */
@@ -305,11 +300,16 @@ PHP_FUNCTION(jwt_encode)
305300
306301 smart_str_0 (& segments );
307302
303+ encode_done :
308304 /* free */
309- efree (sig );
305+ if (sig )
306+ efree (sig );
307+
310308 jwt_free (jwt );
311-
312- RETURN_STR (segments .s );
309+
310+ if (segments .s ) {
311+ RETURN_STR (segments .s );
312+ }
313313}
314314
315315PHP_FUNCTION (jwt_decode )
@@ -365,8 +365,8 @@ PHP_FUNCTION(jwt_decode)
365365
366366 if (!json_h ) {
367367 zend_throw_exception (zend_ce_exception , "Base64 decode error" , 0 );
368- goto decode_done ;
369- }
368+ goto decode_done ;
369+ }
370370
371371 php_json_decode_ex (& zv , ZSTR_VAL (json_h ), ZSTR_LEN (json_h ), PHP_JSON_OBJECT_AS_ARRAY , 512 );
372372 zend_string_free (json_h );
@@ -433,7 +433,7 @@ PHP_MINFO_FUNCTION(jwt)
433433
434434 /* openssl version info */
435435 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 );
437437
438438 php_info_print_table_end ();
439439}
0 commit comments