Bug Summary

File:libglusterfs/src/event-history.c
Location:line 32, column 25
Description:Access to field 'buffer' results in a dereference of a null pointer (loaded from variable 'history')

Annotated Source Code

1/*
2 Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
3 This file is part of GlusterFS.
4
5 This file is licensed to you under your choice of the GNU Lesser
6 General Public License, version 3 or any later version (LGPLv3 or
7 later), or the GNU General Public License, version 2 (GPLv2), in all
8 cases as published by the Free Software Foundation.
9*/
10
11#include "event-history.h"
12
13eh_t *
14eh_new (size_t buffer_size, gf_boolean_t use_buffer_once)
15{
16 eh_t *history = NULL((void*)0);
17 buffer_t *buffer = NULL((void*)0);
18
19 history = GF_CALLOC (1, sizeof (eh_t), gf_common_mt_eh_t)__gf_calloc (1, sizeof (eh_t), gf_common_mt_eh_t);
20 if (!history) {
1
Assuming 'history' is non-null
2
Taking false branch
21 gf_log ("", GF_LOG_ERROR, "allocating history failed.")do { do { if (0) printf ("allocating history failed."); } while
(0); _gf_log ("", "event-history.c", __FUNCTION__, 21, GF_LOG_ERROR
, "allocating history failed."); } while (0)
;
22 goto out;
23 }
24
25 buffer = cb_buffer_new (buffer_size, use_buffer_once);
26 if (!buffer) {
3
Assuming 'buffer' is null
4
Taking true branch
27 gf_log ("", GF_LOG_ERROR, "allocating circular buffer failed")do { do { if (0) printf ("allocating circular buffer failed")
; } while (0); _gf_log ("", "event-history.c", __FUNCTION__, 27
, GF_LOG_ERROR, "allocating circular buffer failed"); } while
(0)
;
28 GF_FREE (history)__gf_free (history);
29 history = NULL((void*)0);
5
Null pointer value stored to 'history'
30 }
31
32 history->buffer = buffer;
6
Access to field 'buffer' results in a dereference of a null pointer (loaded from variable 'history')
33
34 pthread_mutex_init (&history->lock, NULL((void*)0));
35out:
36 return history;
37}
38
39void
40eh_dump (eh_t *history, void *data,
41 int (dump_fn) (circular_buffer_t *buffer, void *data))
42{
43 if (!history) {
44 gf_log ("", GF_LOG_DEBUG, "history is NULL")do { do { if (0) printf ("history is NULL"); } while (0); _gf_log
("", "event-history.c", __FUNCTION__, 44, GF_LOG_DEBUG, "history is NULL"
); } while (0)
;
45 goto out;
46 }
47
48 cb_buffer_dump (history->buffer, data, dump_fn);
49
50out:
51 return;
52}
53
54int
55eh_save_history (eh_t *history, void *data)
56{
57 int ret = -1;
58
59 ret = cb_add_entry_buffer (history->buffer, data);
60
61 return ret;
62}
63
64int
65eh_destroy (eh_t *history)
66{
67 if (!history) {
68 gf_log ("", GF_LOG_INFO, "history for the xlator is "do { do { if (0) printf ("history for the xlator is " "NULL")
; } while (0); _gf_log ("", "event-history.c", __FUNCTION__, 69
, GF_LOG_INFO, "history for the xlator is " "NULL"); } while (
0)
69 "NULL")do { do { if (0) printf ("history for the xlator is " "NULL")
; } while (0); _gf_log ("", "event-history.c", __FUNCTION__, 69
, GF_LOG_INFO, "history for the xlator is " "NULL"); } while (
0)
;
70 return -1;
71 }
72
73 cb_buffer_destroy (history->buffer);
74 history->buffer = NULL((void*)0);
75
76 pthread_mutex_destroy (&history->lock);
77
78 GF_FREE (history)__gf_free (history);
79
80 return 0;
81}