]> git.feebdaed.xyz Git - 0xmirror/radare2.git/commitdiff
Fix last deadcode and resource leak bugs from coverity
authorpancake <pancake@nopcode.org>
Mon, 15 Dec 2025 14:58:11 +0000 (15:58 +0100)
committerpancake <pancake@nopcode.org>
Mon, 15 Dec 2025 14:58:11 +0000 (15:58 +0100)
- CID 1643759 (DEADCODE) - libr/muta/charset.c:159
  - Removed redundant ternary (consumed > 0) ? consumed : 1 since consumed is always ≥1 at that point
- CID 1643758 & 1643755 (RESOURCE_LEAK) - libr/core/core.c
  - Added free(obuf) in all exit paths of r_core_charset_decode_cb() and r_core_charset_encode_cb()
  - Fixed both early return paths (when olen < 1 or cpy allocation fails) and the success path
- CID 1643757 (RESOURCE_LEAK) - libr/muta/p/muta_charset_katakana.c and libr/muta/p/muta_charset_jis7.c
  - Moved free(out) outside the if block so it's always called regardless of the condition
- CID 1643756 (RESOURCE_LEAK) - libr/util/syscmd.c:50
  - Added free(safe) before the early return when strdup() fails

libr/core/core.c
libr/muta/charset.c
libr/muta/p/muta_charset_jis7.c
libr/muta/p/muta_charset_katakana.c
libr/util/syscmd.c

index 0e93de64de5fc626ab2ae80659bca321d55676bb..1d452ef00d63b86082e3fe3dc41f8bc01db55e52 100644 (file)
@@ -1275,17 +1275,20 @@ int r_core_charset_decode_cb(void *ctx, const ut8 *in, int len, ut8 **out, int *
        int olen = 0;
        ut8 *obuf = r_muta_session_get_output (core->charset_session, &olen);
        if (olen < 1) {
+               free (obuf);
                *out = NULL;
                core->charset_session->output_len = 0;
                return 0;
        }
        ut8 *cpy = malloc (olen + 1);
        if (!cpy) {
+               free (obuf);
                *out = NULL;
                core->charset_session->output_len = 0;
                return 0;
        }
        memcpy (cpy, obuf, olen);
+       free (obuf);
        cpy[olen] = 0;
        *out = cpy;
        core->charset_session->output_len = 0;
@@ -1303,17 +1306,20 @@ int r_core_charset_encode_cb(void *ctx, const ut8 *in, int len, ut8 **out) {
        int olen = 0;
        ut8 *obuf = r_muta_session_get_output (c->charset_session, &olen);
        if (olen < 1) {
+               free (obuf);
                *out = NULL;
                c->charset_session->output_len = 0;
                return 0;
        }
        ut8 *cpy = malloc (olen);
        if (!cpy) {
+               free (obuf);
                *out = NULL;
                c->charset_session->output_len = 0;
                return 0;
        }
        memcpy (cpy, obuf, olen);
+       free (obuf);
        *out = cpy;
        c->charset_session->output_len = 0;
        return olen;
index 01d7134823a1c73400fc63216049bdd08f290ae1..d2950051ccd9ef6320db7e2ff855ef1d404f9733 100644 (file)
@@ -156,7 +156,7 @@ R_API ut8 *r_muta_charset_decode(const ut8 *in, int in_len, int *out_len, const
                        consumed = 1;
                }
 
-               ptr += (consumed > 0)? consumed: 1;
+               ptr += consumed;
 
                if (!text || len <= 0) {
                        continue;
index fa369810ee9dda17f5cd32ed77e780d4d418aca4..e57729f7f3a719892c8ad222e41f7b9d41d2ddfe 100644 (file)
@@ -53,10 +53,10 @@ static bool update(RMutaSession *cj, const ut8 *b, int l) {
                        int olen = decode (cj, b + i, l - i, &out, &consumed);
                        if (olen > 0 && out) {
                                r_muta_session_append (cj, out, olen);
-                               free (out);
                        } else {
                                r_muta_session_append (cj, (const ut8 *)"?", 1);
                        }
+                       free (out);
                        if (consumed < 1) {
                                consumed = 1;
                        }
index b986ce4fd682824a39a00527c0ebe295b2bbfaa9..4c3fa949f1dc17efdfde0142382ac202afcc8717 100644 (file)
@@ -59,8 +59,8 @@ static bool update(RMutaSession *cj, const ut8 *b, int l) {
                        int olen = decode (cj, b + i, l - i, &out, &consumed);
                        if (olen > 0 && out) {
                                r_muta_session_append (cj, out, olen);
-                               free (out);
                        }
+                       free (out);
                        if (consumed < 1) {
                                consumed = 1;
                        }
index e2e4ff6f3ae83fced16f09cf0a96aaad3fbd673d..aef8a65af5ac319a72ce56bd74b70b488efa4120 100644 (file)
@@ -46,6 +46,7 @@ static void showfile(RStrBuf *sb, PJ *pj, const int nth, const char *fpath, cons
                gid = st.st_gid;
                perm = st.st_mode & 0777;
                if (! (u_rwx = strdup (r_str_rwx_i (perm >> 6)))) {
+                       free (safe);
                        free (nn);
                        return;
                }