Skip to content
Permalink
Browse files
[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 f3a0167872b501c41cd3d3b522cf2455c5e60266
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/usb_moded-modules.c
@@ -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

0 comments on commit f3a0167

Please sign in to comment.