Commit f3a01678 authored by spiiroin's avatar spiiroin

[modules] Clear context pointer after dropping reference

Not explicitly initializing the pointer to null value makes the validity
of the initial state subject to compiler/libc level implementation details.
And not clearing the pointer after dropping the reference can lead to
hard to debug issues if the potentially state pointer is used later on.

Explicitly initialize the context to null value and set it back to null
after dropping the reference.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent b3e2f370
......@@ -2,10 +2,12 @@
@file usb_moded-modules.c
Copyright (C) 2010 Nokia Corporation. All rights reserved.
Copyright (C) 2012-2015 Jolla. All rights reserved.
Copyright (C) 2012-2016 Jolla. All rights reserved.
@author: Philippe De Swert <philippe.de-swert@nokia.com>
@author: Philippe De Swert <philippe.deswert@jollamobile.com>
@author: Slava Monich <slava.monich@jolla.com>
@author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
......@@ -43,7 +45,7 @@
/* kmod context - initialized at start in usb_moded_init by ctx_init()
and cleaned up by ctx_cleanup() functions */
struct kmod_ctx *ctx;
static struct kmod_ctx *ctx = 0;
/* kmod module init */
void usb_moded_module_ctx_init(void)
......@@ -55,7 +57,8 @@ void usb_moded_module_ctx_init(void)
/* kmod module cleanup */
void usb_moded_module_ctx_cleanup(void)
{
kmod_unref(ctx);
if( ctx )
kmod_unref(ctx), ctx = 0;
}
/** load module
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment