]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - command.c
sideband: Fix use after free bug.
[paraslash.git] / command.c
index 2cac57f90637f8aa42635700a58b77a688b3ff5d..72f8e04e7fe949c89bba065c857a0e7d9ab0820c 100644 (file)
--- a/command.c
+++ b/command.c
@@ -1107,19 +1107,17 @@ net_err:
 out:
        free(buf);
        free(command);
-       sc_free(cc->scc.recv);
-       sc_free(cc->scc.send);
        mutex_lock(mmd_mutex);
        if (cc->cmd && (cc->cmd->perms & AFS_WRITE) && ret >= 0)
                mmd->events++;
        mmd->active_connections--;
        mutex_unlock(mmd_mutex);
-       if (ret < 0)
-               exit(EXIT_FAILURE);
-       if (!cc->use_sideband)
-               exit(EXIT_SUCCESS);
-       ret = send_sb(&cc->scc, NULL, 0, SBD_EXIT__SUCCESS, true);
-       if (ret < 0)
-               PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
+       if (ret >= 0 && cc->use_sideband) {
+               ret = send_sb(&cc->scc, NULL, 0, SBD_EXIT__SUCCESS, true);
+               if (ret < 0)
+                       PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
+       }
+       sc_free(cc->scc.recv);
+       sc_free(cc->scc.send);
        exit(ret < 0? EXIT_FAILURE : EXIT_SUCCESS);
 }