8000 gie: fix memory leak on non existing input file by rouault · Pull Request #4531 · OSGeo/PROJ · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gie: fix memory leak on non existing input file #4531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/apps/cct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ int main(int argc, char **argv) {
/* coverity[tainted_data] */
o = opt_parse(argc, argv, "hvI", "cdozts", longflags, longkeys);
if (nullptr == o)
return 0;
return 1;

if (opt_given(o, "h") || argc == 1) {
printf(usage, o->progname);
free(o);
return 0;
}

Expand All @@ -258,6 +259,7 @@ int main(int argc, char **argv) {

if (opt_given(o, "version")) {
print(PJ_LOG_NONE, "%s: %s", o->progname, pj_get_release());
free(o);
return 0;
}

Expand Down Expand Up @@ -419,6 +421,7 @@ int main(int argc, char **argv) {
/* fail if an inverse operation is not available */
if (!info.has_inverse) {
print(PJ_LOG_ERROR, "Inverse operation not available");
free(o);
if (stdout != fout)
fclose(fout);
return 1;
Expand Down
5 changes: 3 additions & 2 deletions src/apps/gie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ int main(int argc, char **argv) {
/* coverity[tainted_data] */
o = opt_parse(argc, argv, "hlvq", "o", longflags, longkeys);
if (nullptr == o)
return 0;
return 1;

if (opt_given(o, "h") || argc == 1) {
printf(usage, o->progname);
Expand Down Expand Up @@ -335,8 +335,9 @@ int main(int argc, char **argv) {
for (i = 0; i < o->fargc; i++) {
FILE *f = fopen(o->fargv[i], "rt");
if (f == nullptr) {
fprintf(T.fout, "%sCannot open specified input file '%s' - bye!\n",
fprintf(stderr, "%sCannot open specified input file '%s' - bye!\n",
delim, o->fargv[i]);
free(o);
return 1;
}
fclose(f);
Expand Down
6 changes: 6 additions & 0 deletions test/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ endif()
if(BUILD_PROJSYNC)
set(PROJSYNC_EXE "$<TARGET_FILE:projsync>")
endif()
if(BUILD_GIE)
set(GIE_EXE "$<TARGET_FILE:gie>")
endif()

if(UNIX)
if(BUILD_CS2CS)
Expand Down Expand Up @@ -123,6 +126,9 @@ if(Python_for_cli_tests)
if(BUILD_PROJINFO)
proj_run_cli_test(test_projinfo.yaml PROJINFO_EXE)
endif()
if(BUILD_GIE)
proj_run_cli_test(test_gie.yaml GIE_EXE)
endif()

# auto-test run_cli_test.py if pytest available
find_Python_package("pytest" HAS_PYTEST)
Expand Down
14 changes: 14 additions & 0 deletions test/cli/test_cct.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
exe: cct
tests:

- comment: Test version argument
args: --version
sub: ["cct(_d)?(\\.exe)?: Rel.*", "cct: Rel"]
stdout: "cct: Rel"
exitcode: 0

- comment: Test help argument
args: -h
grep: "Usage: "
sub: ["cct(_d)?(\\.exe)?", "cct"]
stdout: "Usage: cct [-options]... [+operator_specs]... infile..."
exitcode: 0

- args: -d 8 +proj=merc +R=1
in: 90 45 0
out: " 1.57079633 0.88137359 0.00000000 inf"
Expand Down
24 changes: 24 additions & 0 deletions test/cli/test_gie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
exe: gie
tests:
- comment: Test invalid argument
args: --invalid
stderr: "Invalid option \"invalid\""
exitcode: 1

- comment: Test version argument
args: --version
sub: ["gie(_d)?(\\.exe)?: Rel.*", "gie: Rel"]
stdout: "gie: Rel"
exitcode: 0

- comment: Test help argument
args: -h
grep: "Usage: "
sub: ["gie(_d)?(\\.exe)?", "gie"]
stdout: "Usage: gie [-options]... infile..."
exitcode: 0

- comment: Test gie with non existing input file
args: i_do_not_exist.txt
stderr: "-------------------------------------------------------------------------------\nCannot open specified input file 'i_do_not_exist.txt' - bye!\n"
exitcode: 1
0