Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Nov 7, 2016
1 parent b3e2f37 commit f3a0167
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/usb_moded-modules.c
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit f3a0167

Please sign in to comment.