Skip to content

Commit 3fcebe4

Browse files
committed
Fix new coverity warnings from refactoring
1 parent 6cb7e59 commit 3fcebe4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/simple_http.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ http_get(const int sockfd, const char *req)
9999
} else if (numbytes == 0) {
100100
done = 1;
101101
} else {
102+
readbuf[numbytes] = '\0';
102103
pstr_cat(response, readbuf);
103104
debug(LOG_DEBUG, "Read %d bytes", numbytes);
104105
}
@@ -117,7 +118,9 @@ http_get(const int sockfd, const char *req)
117118
return retval;
118119

119120
error:
120-
close(sockfd);
121+
if (sockfs >= 0) {
122+
close(sockfd);
123+
}
121124
retval = pstr_to_string(response);
122125
free(retval);
123126
return NULL;
@@ -286,6 +289,7 @@ https_get(const int sockfd, const char *req, const char *hostname)
286289
connection. We can't distinguish between these cases right now. */
287290
done = 1;
288291
} else {
292+
readbuf[numbytes] = '\0';
289293
pstr_cat(response, readbuf);
290294
debug(LOG_DEBUG, "Read %d bytes", numbytes);
291295
}
@@ -310,7 +314,9 @@ https_get(const int sockfd, const char *req, const char *hostname)
310314
if (ssl) {
311315
CyaSSL_free(ssl);
312316
}
313-
close(sockfd);
317+
if (sockfd >= 0) {
318+
close(sockfd);
319+
}
314320
retval = pstr_to_string(response);
315321
free(retval);
316322
return NULL;

0 commit comments

Comments
 (0)