[vlc-commits] [Git][videolan/vlc][master] 5 commits: smb2: homogenize status and error functions

Thomas Guillem (@tguillem) gitlab at videolan.org
Wed Apr 20 12:36:24 UTC 2022



Thomas Guillem pushed to branch master at VideoLAN / VLC


Commits:
e9acccac by Thomas Guillem at 2022-04-20T12:11:47+00:00
smb2: homogenize status and error functions

- - - - -
93b55c9f by Thomas Guillem at 2022-04-20T12:11:47+00:00
smb2: rework error handling from smb2_service_fd

- - - - -
0d51ab8a by Thomas Guillem at 2022-04-20T12:11:47+00:00
smb2: return errno directly

No changes since this function is only checked for != 0 (for now).

- - - - -
5264a625 by Thomas Guillem at 2022-04-20T12:11:47+00:00
smb2: also clear op->smb2 in case of error

op->smb2 won't be used in case of error but it is cleaner like that.

- - - - -
960ef3f8 by Thomas Guillem at 2022-04-20T12:11:47+00:00
smb2: destroy the context in case or errors from smb2_generic_cb

Errors can also be reported via generic cbs, that will cause the
vlc_smb2_mainloop to abort. In that case, we should destroy the smb2
context to fix the issue mentioned by 924c951518f02dd05436d46323301702df516f4f

- - - - -


1 changed file:

- modules/access/smb2.c


Changes:

=====================================
modules/access/smb2.c
=====================================
@@ -155,7 +155,7 @@ vlc_smb2_op_reset(struct vlc_smb2_op *op, struct smb2_context **smb2p)
 }
 
 static int
-smb2_check_status(struct vlc_smb2_op *op, int status, const char *psz_func)
+smb2_check_status(struct vlc_smb2_op *op, const char *psz_func, int status)
 {
     if (status < 0)
     {
@@ -178,17 +178,17 @@ smb2_set_error(struct vlc_smb2_op *op, const char *psz_func, int err)
     if (op->log && err != -EINTR)
         vlc_error(op->log, "%s failed: %d, %s", psz_func, err, smb2_get_error(op->smb2));
 
-    if (err != 0)
+    /* Don't override if set via smb2_check_status */
+    if (op->error_status == 0)
         op->error_status = err;
-    else if (op->error_status == 0) /* don't override if set via smb2_check_status */
-        op->error_status = -EINVAL;
 
     smb2_destroy_context(op->smb2);
+    op->smb2 = NULL;
     *op->smb2p = NULL;
 }
 
 #define VLC_SMB2_CHECK_STATUS(op, status) \
-    smb2_check_status(op, status, __func__)
+    smb2_check_status(op, __func__, status)
 
 #define VLC_SMB2_SET_ERROR(op, func, err) \
     smb2_set_error(op, func, err)
@@ -221,7 +221,7 @@ vlc_smb2_mainloop(struct vlc_smb2_op *op)
         else if (ret == 0)
         {
             if (smb2_service_fd(op->smb2, -1, 0) < 0)
-                VLC_SMB2_SET_ERROR(op, "smb2_service", 0);
+                VLC_SMB2_SET_ERROR(op, "smb2_service", -EINVAL);
         }
         else
         {
@@ -229,13 +229,22 @@ vlc_smb2_mainloop(struct vlc_smb2_op *op)
             {
                 if (p_fds[i].revents
                  && smb2_service_fd(op->smb2, p_fds[i].fd, p_fds[i].revents) < 0)
-                    VLC_SMB2_SET_ERROR(op, "smb2_service", 0);
+                    VLC_SMB2_SET_ERROR(op, "smb2_service", -EINVAL);
             }
         }
     }
 
-    int ret = op->error_status == 0 ? 0 : -1;
-    return ret;
+    if (op->error_status != 0 && op->smb2 != NULL)
+    {
+        /* An error was signalled from a smb2 cb. Destroy the smb2 context now
+         * since this call might still trigger callbacks using the current op
+         * (that is allocated on the stack). */
+        smb2_destroy_context(op->smb2);
+        op->smb2 = NULL;
+        *op->smb2p = NULL;
+    }
+
+    return op->error_status;
 }
 
 #define VLC_SMB2_GENERIC_CB() \



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/38891c2dc35b7903c39cef2f43730da3a2a50a42...960ef3f8ef74e352d5e3caa42f49cce8a686c8b3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/38891c2dc35b7903c39cef2f43730da3a2a50a42...960ef3f8ef74e352d5e3caa42f49cce8a686c8b3
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list