Fix resource and memory leaks in examples as reported by cppcheck
Thanks to Ettl Martin for the report and patch. This fixes #132
This commit is contained in:
parent
a491017f5a
commit
2149244cfe
@ -197,6 +197,8 @@ int main(int argc, char *argv[])
|
|||||||
#else
|
#else
|
||||||
close(sock);
|
close(sock);
|
||||||
#endif
|
#endif
|
||||||
|
if (local)
|
||||||
|
fclose(local);
|
||||||
fprintf(stderr, "all done\n");
|
fprintf(stderr, "all done\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -283,6 +283,8 @@ int main(int argc, char *argv[])
|
|||||||
#else
|
#else
|
||||||
close(sock);
|
close(sock);
|
||||||
#endif
|
#endif
|
||||||
|
if (tempstorage)
|
||||||
|
fclose(tempstorage);
|
||||||
printf("all done\n");
|
printf("all done\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -184,12 +184,10 @@ int main(int argc, char *argv[])
|
|||||||
} while (rc > 0);
|
} while (rc > 0);
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
||||||
fclose(local);
|
|
||||||
libssh2_sftp_close(sftp_handle);
|
libssh2_sftp_close(sftp_handle);
|
||||||
libssh2_sftp_shutdown(sftp_session);
|
libssh2_sftp_shutdown(sftp_session);
|
||||||
|
|
||||||
shutdown:
|
shutdown:
|
||||||
|
|
||||||
libssh2_session_disconnect(session,
|
libssh2_session_disconnect(session,
|
||||||
"Normal Shutdown, Thank you for playing");
|
"Normal Shutdown, Thank you for playing");
|
||||||
libssh2_session_free(session);
|
libssh2_session_free(session);
|
||||||
@ -199,6 +197,8 @@ int main(int argc, char *argv[])
|
|||||||
#else
|
#else
|
||||||
close(sock);
|
close(sock);
|
||||||
#endif
|
#endif
|
||||||
printf("all done\n");
|
if (local)
|
||||||
|
fclose(local);
|
||||||
|
printf("all done\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -121,11 +121,16 @@ static void x11_callback(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel,
|
|||||||
/* Connect to the local unix domain */
|
/* Connect to the local unix domain */
|
||||||
ptr = strrchr(display, ':');
|
ptr = strrchr(display, ':');
|
||||||
temp_buff = (char *) calloc(strlen(ptr+1), sizeof(char));
|
temp_buff = (char *) calloc(strlen(ptr+1), sizeof(char));
|
||||||
|
if (!temp_buff) {
|
||||||
|
perror("calloc");
|
||||||
|
return;
|
||||||
|
}
|
||||||
memcpy(temp_buff, ptr+1, strlen(ptr+1));
|
memcpy(temp_buff, ptr+1, strlen(ptr+1));
|
||||||
display_port = atoi(temp_buff);
|
display_port = atoi(temp_buff);
|
||||||
|
free(temp_buff);
|
||||||
|
|
||||||
sock = socket(AF_UNIX,SOCK_STREAM, 0);
|
sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sock <0)
|
if (sock < 0)
|
||||||
return;
|
return;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
|
Loading…
Reference in New Issue
Block a user