Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIMSignalingAPI.cs中SignalingCreate等方法传参结构体释放不完整问题 #3

Open
dujianxin opened this issue Mar 19, 2020 · 0 comments

Comments

@dujianxin
Copy link
Contributor

传参结构体param_c在构建时为channel_ext_分配内存,调用完成后,仅针对param_c释放,未针对channel_ext_释放,存在内存泄露问题,请确认。

        public static NIMSignalingCreateParam_C GetNativeNIMSignalingCreateParam(NIMSignalingCreateParam param)
        {
            NIMSignalingCreateParam_C param_c = new NIMSignalingCreateParam_C();
            if(param!=null)
            {
                param_c.channel_ext_ = Utf8StringMarshaler.GetInstance("").MarshalManagedToNative(param.channel_ext_); 
                param_c.channel_name_= Utf8StringMarshaler.GetInstance("").MarshalManagedToNative(param.channel_name_); 
                param_c.channel_type_ = param.channel_type_;
                
            }
            return param_c;
        }
        public static void SignalingCreate(NIMSignalingCreateParam param, NimSignalingOptCreateHandler cb)
        {
            NIMSignalingCreateParam_C param_c = SignalHelper.GetNativeNIMSignalingCreateParam(param);
            int nSizeOfParam = Marshal.SizeOf(param_c);
            IntPtr param_ptr = Marshal.AllocHGlobal(nSizeOfParam);
            try
            {
                Marshal.StructureToPtr(param_c, param_ptr, false);
                var user_ptr = NimUtility.DelegateConverter.ConvertToIntPtr(cb);
                SignalingNativeMethods.nim_signaling_create(param_ptr, NimSignalingCreateCb, user_ptr);
            }
            catch (Exception)
            {
                cb?.Invoke(NIMSignalingCreateResCode.kAbnormal, null);
            }
            finally
            {
                Marshal.FreeHGlobal(param_ptr);
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant