Bug Summary

File:obj-scan-build/ftpfs/../../ftpfs/ncache.c
Location:line 32, column 24
Description:Access to field 'nn' results in a dereference of a null pointer (loaded from variable 'node')

Annotated Source Code

1/* Node caching
2
3 Copyright (C) 1997 Free Software Foundation, Inc.
4 Written by Miles Bader <miles@gnu.ai.mit.edu>
5 This file is part of the GNU Hurd.
6
7 The GNU Hurd is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
11
12 The GNU Hurd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
20
21#include <unistd.h>
22#include <string.h>
23
24#include <hurd/netfs.h>
25
26#include "ftpfs.h"
27
28/* Remove NN's node from its position in FS's node cache. */
29static void
30node_unlink (struct node *node, struct ftpfs *fs)
31{
32 struct netnode *nn = node->nn;
7
Access to field 'nn' results in a dereference of a null pointer (loaded from variable 'node')
33 if (nn->ncache_next)
34 nn->ncache_next->nn->ncache_prev = nn->ncache_prev;
35 if (nn->ncache_prev)
36 nn->ncache_prev->nn->ncache_next = nn->ncache_next;
37 if (fs->node_cache_mru == node)
38 fs->node_cache_mru = nn->ncache_next;
39 if (fs->node_cache_lru == node)
40 fs->node_cache_lru = nn->ncache_prev;
41 nn->ncache_next = 0;
42 nn->ncache_prev = 0;
43 fs->node_cache_len--;
44}
45
46/* Add NODE to the recently-used-node cache, which adds a reference to
47 prevent it from going away. NODE should be locked. */
48void
49ftpfs_cache_node (struct node *node)
50{
51 struct netnode *nn = node->nn;
52 struct ftpfs *fs = nn->fs;
53
54 pthread_mutex_lock (&fs->node_cache_lock);
55
56 if (fs->params.node_cache_max > 0 || fs->node_cache_len > 0)
57 {
58 if (fs->node_cache_mru != node)
1
Taking false branch
59 {
60 if (nn->ncache_next || nn->ncache_prev)
61 /* Node is already in the cache. */
62 node_unlink (node, fs);
63 else
64 /* Add a reference from the cache. */
65 netfs_nref (node);
66
67 nn->ncache_next = fs->node_cache_mru;
68 nn->ncache_prev = 0;
69 if (fs->node_cache_mru)
70 fs->node_cache_mru->nn->ncache_prev = node;
71 if (! fs->node_cache_lru)
72 fs->node_cache_lru = node;
73 fs->node_cache_mru = node;
74 fs->node_cache_len++;
75 }
76
77 /* Forget the least used nodes. */
78 while (fs->node_cache_len > fs->params.node_cache_max)
2
Loop condition is true. Entering loop body
3
Loop condition is true. Entering loop body
79 {
80 struct node *lru = fs->node_cache_lru;
4
Variable 'lru' initialized to a null pointer value
81 node_unlink (lru, fs);
5
Passing null pointer value via 1st parameter 'node'
6
Calling 'node_unlink'
82 netfs_nrele (lru);
83 }
84 }
85
86 pthread_mutex_unlock (&fs->node_cache_lock);
87}