Jiri Danek created ARTEMIS-1414:
-----------------------------------
Summary: Coverity: Resource leak on an exceptional path in
ArtemisCreatePlugin.java
Key: ARTEMIS-1414
URL: https://issues.apache.org/jira/browse/ARTEMIS-1414
Project: ActiveMQ Artemis
Issue Type: Bug
Components: Broker
Affects Versions: 2.4.0
Reporter: Jiri Danek
Priority: Trivial
{noformat}
147 @Override
148 protected void doExecute() throws MojoExecutionException,
MojoFailureException {
149 getLog().info("Local " + localRepository);
CID 1418665: DLS: Dead local store (FB.DLS_DEAD_LOCAL_STORE) [select
issue]
150 MavenProject project = (MavenProject)
getPluginContext().get("project");
151
1. Condition !isArtemisHome(home.toPath()), taking true branch.
152 if (!isArtemisHome(home.toPath())) {
2. Condition isArtemisHome(alternateHome.toPath()), taking true branch.
153 if (isArtemisHome(alternateHome.toPath())) {
154 home = alternateHome;
3. Falling through to end of if statement.
155 } else {
156
getLog().error("********************************************************************************************");
157 getLog().error("Could not locate suitable Artemis.home on either
" + home + " or " + alternateHome);
158 getLog().error("Use the binary distribution or build the
distribution before running the examples");
159
getLog().error("********************************************************************************************");
160
161 throw new MojoExecutionException("Couldn't find artemis.home");
162 }
163 }
164
165 Map properties = getPluginContext();
166
167 Set<Map.Entry> entries = properties.entrySet();
168
169 getLog().info("Entries.size " + entries.size());
4. Iterating over another element of entries.
6. No elements left in entries, leaving loop.
170 for (Map.Entry entry : entries) {
171 getLog().info("... key=" + entry.getKey() + " = " +
entry.getValue());
5. Jumping back to the beginning of the loop.
172 }
173
174 ArrayList<String> listCommands = new ArrayList<>();
175
176 add(listCommands, "create", "--allow-anonymous", "--silent",
"--force", "--no-web", "--user", user, "--password", password, "--role", role,
"--port-offset", "" + portOffset, "--data", dataFolder);
177
7. Condition allowAnonymous, taking true branch.
178 if (allowAnonymous) {
179 add(listCommands, "--allow-anonymous");
8. Falling through to end of if statement.
180 } else {
181 add(listCommands, "--require-login");
182 }
183
9. Condition !javaOptions.isEmpty(), taking false branch.
184 if (!javaOptions.isEmpty()) {
185 add(listCommands, "--java-options", javaOptions);
186 }
187
10. Condition slave, taking true branch.
188 if (slave) {
189 add(listCommands, "--slave");
190 }
191
11. Condition replicated, taking true branch.
192 if (replicated) {
193 add(listCommands, "--replicated");
194 }
195
12. Condition sharedStore, taking true branch.
196 if (sharedStore) {
197 add(listCommands, "--shared-store");
198 }
199
13. Condition clustered, taking true branch.
200 if (clustered) {
201 add(listCommands, "--clustered");
202 add(listCommands, "--message-load-balancing", messageLoadBalancing);
203 }
204
14. Condition failoverOnShutdown, taking true branch.
205 if (failoverOnShutdown) {
206 add(listCommands, "--failover-on-shutdown");
207 }
208
15. Condition noAutoTune, taking true branch.
209 if (noAutoTune) {
210 add(listCommands, "--no-autotune");
211 }
212
213 add(listCommands, "--verbose");
214
16. Condition "Linux".equals(java.lang.System.getProperty("os.name")),
taking false branch.
215 if ("Linux".equals(System.getProperty("os.name"))) {
216 add(listCommands, "--aio");
217 }
218
17. Iterating over another element of args.
19. No elements left in args, leaving loop.
219 for (String str : args) {
220 add(listCommands, str);
18. Jumping back to the beginning of the loop.
221 }
222
223 add(listCommands, instance.getAbsolutePath());
224
225 getLog().debug("***** Server created at " + instance + " with home=" +
home + " *****");
226
227 File commandLine = new File(instance.getParentFile(), "create-" +
instance.getName() + ".sh");
228 FileOutputStream outputStream;
229 try {
20. new_resource: new java.io.FileOutputStream(commandLine) creates a
new resource.
21. var_assign: Assigning: outputStream = resource returned from new
java.io.FileOutputStream(commandLine).
230 outputStream = new FileOutputStream(commandLine);
22. Falling through to end of try statement.
231 } catch (Exception e) {
232 e.printStackTrace();
233 throw new MojoExecutionException(e.getMessage(), e);
234 }
235
CID 1418823: Dm: Dubious method used (FB.DM_DEFAULT_ENCODING) [select
issue]
23. var_assign: Assigning: commandLineStream = resource returned from
new java.io.PrintStream(outputStream).
236 PrintStream commandLineStream = new PrintStream(outputStream);
24. noescape: Resource commandLineStream is not closed or saved in
println.
237 commandLineStream.println("# These are the commands used to create " +
instance.getName());
25. noescape: Resource commandLineStream is not closed or saved in
println.
238 commandLineStream.println(getCommandline(listCommands));
239
240 try {
241 Artemis.execute(home, null, listCommands);
242
26. Condition configuration != null, taking true branch.
243 if (configuration != null) {
244 String[] list = configuration.list();
245
27. Condition list != null, taking false branch.
246 if (list != null) {
247
getLog().debug("************************************************");
248 getLog().debug("Copying configuration files:");
249
250 copyConfigurationFiles(list, configuration.toPath(),
instance.toPath().resolve("etc"), commandLineStream);
251 }
252 }
253
28. throw: Throwing
org.eclipse.aether.collection.DependencyCollectionException (or subclass) from
call to resolveDependencies. [show details]
254 Set<File> files = resolveDependencies(libListWithDeps, libList);
255
256 if (!files.isEmpty()) {
257 commandLineStream.println();
258 commandLineStream.println("# This is a list of files that need
to be installed under ./lib.");
259 commandLineStream.println("# We are copying them from your maven
lib home");
260 for (File file : files) {
261 copyToLib(file, commandLineStream);
262 }
263 }
264
265 commandLineStream.close();
266
267 FileUtil.makeExec(commandLine);
268
269
getLog().info("###################################################################################################");
270 getLog().info(commandLine.getName() + " created with commands to
reproduce " + instance.getName());
271 getLog().info("under " + commandLine.getParent());
272
getLog().info("###################################################################################################");
273
29. Catching exception.
274 } catch (Throwable e) {
275 getLog().error(e);
30. Throwing org.apache.maven.plugin.MojoFailureException; exiting
method with uncaught exception.
31. leaked_resource: Variable commandLineStream going out of scope
leaks the resource it refers to.
CID 1409614 (#1 of 1): Resource leak on an exceptional path (RESOURCE_LEAK)
32. leaked_resource: Variable outputStream going out of scope leaks the
resource it refers to.
276 throw new MojoFailureException(e.getMessage());
277 }
278 }
{noformat}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)