protobuf: close a leak when file loading fails.

Free the path we've constructed before returning a failure indication if
pbw_load_proto_file() or load_all_files_in_dir() reports a failure.

Also, explicitly compare pbw_load_proto_file()'s return value against 0,
to make it a little clearer that it's *not* a Boolean, it's a return
code (with 0 meaning success and different non-zero values meaning
failure; if it matters *which* failure it is, we should probably have
otherwise we should just make it a Boolean).
This commit is contained in:
Guy Harris 2021-05-21 18:33:56 -07:00
parent eb75366bc4
commit f1ffe7d421
1 changed files with 3 additions and 1 deletions

View File

@ -1448,11 +1448,13 @@ load_all_files_in_dir(PbwDescriptorPool* pool, const gchar* dir_path)
dot = strrchr(name, '.');
if (dot && g_ascii_strcasecmp(dot + 1, "proto") == 0) {
/* Note: pbw_load_proto_file support absolute or relative (to one of search paths) path */
if (pbw_load_proto_file(pool, path)) {
if (pbw_load_proto_file(pool, path) != 0) {
g_free(path);
return FALSE;
}
} else {
if (!load_all_files_in_dir(pool, path)) {
g_free(path);
return FALSE;
}
}