Bug Summary

File:test_metar.c
Warning:line 73, column 12
Opened file is never closed; potential resource leak

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test_metar.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/libcafeweather -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I .. -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I .. -I . -I /usr/include/libsoup-3.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/libcafeweather -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-08-05-202824-15211-1 -x c test_metar.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2/*
3 * Simple program to reproduce METAR parsing results from command line
4 */
5
6#include <glib.h>
7#include <string.h>
8#include <stdio.h>
9#define CAFEWEATHER_I_KNOW_THIS_IS_UNSTABLE
10#include "weather-priv.h"
11
12#ifndef BUFLEN4096
13#define BUFLEN4096 4096
14#endif /* BUFLEN */
15
16int
17main (int argc, char **argv)
18{
19 FILE* stream = stdinstdin;
20 gchar* filename = NULL((void*)0);
21 GOptionEntry entries[] = {
22 { "file", 'f', 0, G_OPTION_ARG_FILENAME, &filename,
23 "file constaining metar observations", NULL((void*)0) },
24 { NULL((void*)0) }
25 };
26 GOptionContext* context;
27 GError* error = NULL((void*)0);
28 char buf[BUFLEN4096];
29 int len;
30 WeatherInfo info;
31
32 context = g_option_context_new ("- test libcafeweather metar parser");
33 g_option_context_add_main_entries (context, entries, NULL((void*)0));
34 g_option_context_parse (context, &argc, &argv, &error);
35
36 if (error) {
1
Assuming 'error' is null
2
Taking false branch
37 perror (error->message);
38 return error->code;
39 }
40 if (filename) {
3
Assuming 'filename' is non-null
4
Taking true branch
41 stream = fopen (filename, "r");
42 if (!stream) {
5
Assuming 'stream' is non-null
6
Taking false branch
43 perror ("fopen");
44 return -1;
45 }
46 } else {
47 fprintf (stderrstderr, "Enter a METAR string...\n");
48 }
49
50 while (fgets (buf, sizeof (buf), stream)) {
7
Loop condition is false. Execution continues on line 73
51 len = strlen (buf);
52 if (buf[len - 1] == '\n') {
53 buf[--len] = '\0';
54 }
55 printf ("\n%s\n", buf);
56
57 memset (&info, 0, sizeof (info));
58 info.valid = 1;
59 metar_parse (buf, &info);
60 weather_info_to_metric (&info);
61 printf ("Returned info:\n");
62 printf (" update: %s", ctime (&info.update));
63 printf (" sky: %s\n", weather_info_get_sky (&info));
64 printf (" cond: %s\n", weather_info_get_conditions (&info));
65 printf (" temp: %s\n", weather_info_get_temp (&info));
66 printf (" dewp: %s\n", weather_info_get_dew (&info));
67 printf (" wind: %s\n", weather_info_get_wind (&info));
68 printf (" pressure: %s\n", weather_info_get_pressure (&info));
69 printf (" vis: %s\n", weather_info_get_visibility (&info));
70
71 // TODO: retrieve location's lat/lon to display sunrise/set times
72 }
73 return 0;
8
Opened file is never closed; potential resource leak
74}