diff --git a/include/iscsi-private.h b/include/iscsi-private.h index f523b6e..5c9b15a 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -62,14 +62,18 @@ enum iscsi_immediate_data { }; struct iscsi_context { - const char *initiator_name; - const char *target_name; - const char *target_address; /* If a redirect */ - const char *connected_portal; - const char *alias; + char initiator_name[MAX_STRING_SIZE+1]; + char target_name[MAX_STRING_SIZE+1]; + char target_address[MAX_STRING_SIZE+1]; /* If a redirect */ + char connected_portal[MAX_STRING_SIZE+1]; + char portal[MAX_STRING_SIZE+1]; + char alias[MAX_STRING_SIZE+1]; - const char *user; - const char *passwd; + char user[MAX_STRING_SIZE+1]; + char passwd[MAX_STRING_SIZE+1]; + char chap_c[MAX_STRING_SIZE+1]; + + char error_string[MAX_STRING_SIZE+1]; enum iscsi_session_type session_type; unsigned char isid[6]; @@ -80,8 +84,6 @@ struct iscsi_context { enum iscsi_header_digest want_header_digest; enum iscsi_header_digest header_digest; - char *error_string; - int fd; int is_connected; @@ -103,7 +105,6 @@ struct iscsi_context { int chap_a; int chap_i; - char *chap_c; iscsi_command_cb socket_status_cb; void *connect_data; @@ -124,7 +125,6 @@ struct iscsi_context { enum iscsi_immediate_data use_immediate_data; int lun; - const char *portal; int no_auto_reconnect; int reconnect_deferred; int debug; diff --git a/include/iscsi.h b/include/iscsi.h index 8453e5d..0ab4b84 100644 --- a/include/iscsi.h +++ b/include/iscsi.h @@ -32,6 +32,8 @@ extern "C" { struct iscsi_context; struct sockaddr; +#define MAX_STRING_SIZE (255) + /* * Syntax for normal and portal/discovery URLs. */ @@ -69,13 +71,11 @@ EXTERN int iscsi_queue_length(struct iscsi_context *iscsi); */ int iscsi_set_tcp_keepalive(struct iscsi_context *iscsi, int idle, int count, int interval); - - struct iscsi_url { - const char *portal; - const char *target; - const char *user; - const char *passwd; + char portal[MAX_STRING_SIZE+1]; + char target[MAX_STRING_SIZE+1]; + char user[MAX_STRING_SIZE+1]; + char passwd[MAX_STRING_SIZE+1]; int lun; }; @@ -971,7 +971,7 @@ iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi); if ((iscsi)->debug >= level) { \ fprintf(stderr,"libiscsi: "); \ fprintf(stderr, (fmt), ##args); \ - if (iscsi->target_name) { \ + if (iscsi->target_name[0]) { \ fprintf(stderr," [%s]",iscsi->target_name); \ } \ fprintf(stderr,"\n"); \ @@ -1019,6 +1019,12 @@ iscsi_set_tcp_keepcnt(struct iscsi_context *iscsi, int value); EXTERN void iscsi_set_tcp_keepintvl(struct iscsi_context *iscsi, int value); +/* + * This function is to set the TCP_SYNCNT option. It has to be called after iscsi + * context creation. + */ +EXTERN void +iscsi_set_tcp_syncnt(struct iscsi_context *iscsi, int value); #ifdef __cplusplus } diff --git a/lib/connect.c b/lib/connect.c index 7550162..4fce89c 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -61,6 +61,7 @@ iscsi_testunitready_cb(struct iscsi_context *iscsi, int status, "failed."); ct->cb(iscsi, SCSI_STATUS_ERROR, NULL, ct->private_data); + free(ct); } scsi_free_scsi_task(task); return; @@ -79,6 +80,7 @@ iscsi_testunitready_cb(struct iscsi_context *iscsi, int status, ct->cb(iscsi, status?SCSI_STATUS_ERROR:SCSI_STATUS_GOOD, NULL, ct->private_data); scsi_free_scsi_task(task); + free(ct); } static void @@ -87,9 +89,10 @@ iscsi_login_cb(struct iscsi_context *iscsi, int status, void *command_data _U_, { struct connect_task *ct = private_data; - if (status == SCSI_STATUS_REDIRECT && iscsi->target_address) { + if (status == SCSI_STATUS_REDIRECT && iscsi->target_address[0]) { iscsi_disconnect(iscsi); if (iscsi_connect_async(iscsi, iscsi->target_address, iscsi_connect_cb, iscsi->connect_data) != 0) { + free(ct); return; } return; @@ -97,6 +100,7 @@ iscsi_login_cb(struct iscsi_context *iscsi, int status, void *command_data _U_, if (status != 0) { ct->cb(iscsi, SCSI_STATUS_ERROR, NULL, ct->private_data); + free(ct); return; } @@ -117,12 +121,14 @@ iscsi_connect_cb(struct iscsi_context *iscsi, int status, void *command_data _U_ iscsi_set_error(iscsi, "Failed to connect to iSCSI socket. " "%s", iscsi_get_error(iscsi)); ct->cb(iscsi, SCSI_STATUS_ERROR, NULL, ct->private_data); + free(ct); return; } if (iscsi_login_async(iscsi, iscsi_login_cb, ct) != 0) { iscsi_set_error(iscsi, "iscsi_login_async failed."); ct->cb(iscsi, SCSI_STATUS_ERROR, NULL, ct->private_data); + free(ct); } } @@ -134,7 +140,7 @@ iscsi_full_connect_async(struct iscsi_context *iscsi, const char *portal, struct connect_task *ct; iscsi->lun = lun; - iscsi->portal = strdup(portal); + strncpy(iscsi->portal,portal,MAX_STRING_SIZE); ct = malloc(sizeof(struct connect_task)); if (ct == NULL) { @@ -221,7 +227,7 @@ try_again: iscsi_set_header_digest(iscsi, old_iscsi->want_header_digest); - if (old_iscsi->user != NULL) { + if (old_iscsi->user[0]) { iscsi_set_initiator_username_pwd(iscsi, old_iscsi->user, old_iscsi->passwd); } @@ -229,7 +235,7 @@ try_again: iscsi->lun = old_iscsi->lun; - iscsi->portal = strdup(old_iscsi->portal); + strncpy(iscsi->portal,old_iscsi->portal,MAX_STRING_SIZE); iscsi->debug = old_iscsi->debug; @@ -311,26 +317,12 @@ try_again: goto try_again; } - - free(discard_const(old_iscsi->initiator_name)); - free(discard_const(old_iscsi->target_name)); - free(discard_const(old_iscsi->target_address)); - free(discard_const(old_iscsi->alias)); - free(discard_const(old_iscsi->portal)); if (old_iscsi->incoming != NULL) { iscsi_free_iscsi_in_pdu(old_iscsi->incoming); } if (old_iscsi->inqueue != NULL) { iscsi_free_iscsi_inqueue(old_iscsi->inqueue); } - free(old_iscsi->error_string); - free(discard_const(old_iscsi->user)); - free(discard_const(old_iscsi->passwd)); - free(discard_const(old_iscsi->chap_c)); - - if (old_iscsi->connected_portal != NULL) { - free(discard_const(old_iscsi->connected_portal)); - } close(iscsi->fd); iscsi->fd = old_iscsi->fd; diff --git a/lib/init.c b/lib/init.c index 5bd6d0c..533b654 100644 --- a/lib/init.c +++ b/lib/init.c @@ -45,8 +45,8 @@ iscsi_create_context(const char *initiator_name) memset(iscsi, 0, sizeof(struct iscsi_context)); - iscsi->initiator_name = strdup(initiator_name); - if (iscsi->initiator_name == NULL) { + strncpy(iscsi->initiator_name,initiator_name,MAX_STRING_SIZE); + if (!iscsi->initiator_name[0]) { free(iscsi); return NULL; } @@ -169,14 +169,7 @@ iscsi_set_alias(struct iscsi_context *iscsi, const char *alias) return -1; } - free(discard_const(iscsi->alias)); - - iscsi->alias = strdup(alias); - if (iscsi->alias == NULL) { - iscsi_set_error(iscsi, "Failed to allocate alias name"); - return -1; - } - + strncpy(iscsi->alias,alias,MAX_STRING_SIZE); return 0; } @@ -189,13 +182,7 @@ iscsi_set_targetname(struct iscsi_context *iscsi, const char *target_name) return -1; } - free(discard_const(iscsi->target_name)); - - iscsi->target_name = strdup(target_name); - if (iscsi->target_name == NULL) { - iscsi_set_error(iscsi, "Failed to allocate target name"); - return -1; - } + strncpy(iscsi->target_name,target_name,MAX_STRING_SIZE); return 0; } @@ -238,21 +225,6 @@ iscsi_destroy_context(struct iscsi_context *iscsi) iscsi_free_pdu(iscsi, pdu); } - free(discard_const(iscsi->initiator_name)); - iscsi->initiator_name = NULL; - - free(discard_const(iscsi->target_name)); - iscsi->target_name = NULL; - - free(discard_const(iscsi->target_address)); - iscsi->target_address = NULL; - - free(discard_const(iscsi->alias)); - iscsi->alias = NULL; - - free(discard_const(iscsi->portal)); - iscsi->portal = NULL; - if (iscsi->incoming != NULL) { iscsi_free_iscsi_in_pdu(iscsi->incoming); } @@ -260,23 +232,6 @@ iscsi_destroy_context(struct iscsi_context *iscsi) iscsi_free_iscsi_inqueue(iscsi->inqueue); } - free(iscsi->error_string); - iscsi->error_string = NULL; - - free(discard_const(iscsi->user)); - iscsi->user = NULL; - - free(discard_const(iscsi->passwd)); - iscsi->passwd = NULL; - - free(discard_const(iscsi->chap_c)); - iscsi->chap_c = NULL; - - if (iscsi->connected_portal != NULL) { - free(discard_const(iscsi->connected_portal)); - iscsi->connected_portal = NULL; - } - iscsi->connect_data = NULL; free(iscsi); @@ -288,23 +243,16 @@ void iscsi_set_error(struct iscsi_context *iscsi, const char *error_string, ...) { va_list ap; - char *str; + char errstr[MAX_STRING_SIZE+1] = {0}; va_start(ap, error_string); - str = malloc(1024); - if (vsnprintf(str, 1024, error_string, ap) < 0) { - /* not much we can do here */ - free(str); - str = NULL; + if (vsnprintf(errstr, MAX_STRING_SIZE, error_string, ap) < 0) { + strncpy(errstr,"could not format error string!",MAX_STRING_SIZE); } - - free(iscsi->error_string); - - iscsi->error_string = str; - va_end(ap); - DPRINTF(iscsi,1,"%s",str); + strncpy(iscsi->error_string,errstr,MAX_STRING_SIZE); + DPRINTF(iscsi,1,"%s",iscsi->error_string); } void @@ -353,10 +301,10 @@ iscsi_is_logged_in(struct iscsi_context *iscsi) } struct iscsi_url * -iscsi_parse_full_url(struct iscsi_context *iscsi, const char *url) +iscsi_parse_url(struct iscsi_context *iscsi, const char *url, int full) { struct iscsi_url *iscsi_url; - char *str; + char str[MAX_STRING_SIZE+1]; char *portal; char *user = NULL; char *passwd = NULL; @@ -366,18 +314,16 @@ iscsi_parse_full_url(struct iscsi_context *iscsi, const char *url) int l; if (strncmp(url, "iscsi://", 8)) { + if (full) { iscsi_set_error(iscsi, "Invalid URL %s\niSCSI URL must be of " - "the form: %s", - url, - ISCSI_URL_SYNTAX); + "the form: %s",url,ISCSI_URL_SYNTAX); } + else { + iscsi_set_error(iscsi, "Invalid URL %s\niSCSI Portal URL must be of " + "the form: %s",url,ISCSI_PORTAL_URL_SYNTAX); } return NULL; } - str = strdup(url + 8); - if (str == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup url %s", url); - return NULL; - } + strncpy(str,url + 8,MAX_STRING_SIZE); portal = str; user = getenv("LIBISCSI_CHAP_USERNAME"); @@ -397,190 +343,91 @@ iscsi_parse_full_url(struct iscsi_context *iscsi, const char *url) *tmp++ = 0; passwd = tmp; } - } - target = strchr(portal, '/'); - if (target == NULL) { - iscsi_set_error(iscsi, "Invalid URL %s\nCould not parse " + if (full) { + target = strchr(portal, '/'); + if (target == NULL) { + iscsi_set_error(iscsi, "Invalid URL %s\nCould not parse " "''\niSCSI URL must be of the " "form: %s", url, ISCSI_URL_SYNTAX); - free(str); - return NULL; - } - *target++ = 0; + return NULL; + } + *target++ = 0; - if (*target == 0) { - iscsi_set_error(iscsi, "Invalid URL %s\nCould not parse " + if (*target == 0) { + iscsi_set_error(iscsi, "Invalid URL %s\nCould not parse " "\n" "iSCSI URL must be of the form: %s", url, ISCSI_URL_SYNTAX); - free(str); - return NULL; - } + return NULL; + } - lun = strchr(target, '/'); - if (lun == NULL) { - iscsi_set_error(iscsi, "Invalid URL %s\nCould not parse \n" + lun = strchr(target, '/'); + if (lun == NULL) { + iscsi_set_error(iscsi, "Invalid URL %s\nCould not parse \n" "iSCSI URL must be of the form: %s", url, ISCSI_URL_SYNTAX); - free(str); - return NULL; - } - *lun++ = 0; + return NULL; + } + *lun++ = 0; - l = strtol(lun, &tmp, 10); - if (*lun == 0 || *tmp != 0) { - iscsi_set_error(iscsi, "Invalid URL %s\nCould not parse \n" + l = strtol(lun, &tmp, 10); + if (*lun == 0 || *tmp != 0) { + iscsi_set_error(iscsi, "Invalid URL %s\nCould not parse \n" "iSCSI URL must be of the form: %s", url, ISCSI_URL_SYNTAX); - free(str); - return NULL; + return NULL; + } } - + else + { + tmp=strchr(portal,'/'); + if (tmp) *tmp=0; + } + iscsi_url = malloc(sizeof(struct iscsi_url)); if (iscsi_url == NULL) { iscsi_set_error(iscsi, "Out-of-memory: Failed to allocate iscsi_url structure"); - free(str); return NULL; } memset(iscsi_url, 0, sizeof(struct iscsi_url)); - iscsi_url->portal = strdup(portal); - if (iscsi_url->portal == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup portal string"); - iscsi_destroy_url(iscsi_url); - free(str); - return NULL; - } - - iscsi_url->target = strdup(target); - if (iscsi_url->target == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup target string"); - iscsi_destroy_url(iscsi_url); - free(str); - return NULL; - } + strncpy(iscsi_url->portal,portal,MAX_STRING_SIZE); if (user != NULL && passwd != NULL) { - iscsi_url->user = strdup(user); - if (iscsi_url->user == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup username string"); - iscsi_destroy_url(iscsi_url); - free(str); - return NULL; - } - - iscsi_url->passwd = strdup(passwd); - if (iscsi_url->passwd == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup password string"); - iscsi_destroy_url(iscsi_url); - free(str); - return NULL; - } + strncpy(iscsi_url->user,user,MAX_STRING_SIZE); + strncpy(iscsi_url->passwd,passwd,MAX_STRING_SIZE); + } + + if (full) { + strncpy(iscsi_url->target,target,MAX_STRING_SIZE); + iscsi_url->lun = l; } - iscsi_url->lun = l; - free(str); return iscsi_url; } +struct iscsi_url * +iscsi_parse_full_url(struct iscsi_context *iscsi, const char *url) +{ + return iscsi_parse_url(iscsi,url,1); +} + struct iscsi_url * iscsi_parse_portal_url(struct iscsi_context *iscsi, const char *url) { - struct iscsi_url *iscsi_url; - char *str; - char *portal; - char *user = NULL; - char *passwd = NULL; - char *tmp; - - if (strncmp(url, "iscsi://", 8)) { - iscsi_set_error(iscsi, "Invalid URL %s\niSCSI Portal URL must be of " - "the form: %s", - url, - ISCSI_PORTAL_URL_SYNTAX); - return NULL; - } - - str = strdup(url + 8); - if (str == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup url %s", url); - return NULL; - } - portal = str; - - user = getenv("LIBISCSI_CHAP_USERNAME"); - passwd = getenv("LIBISCSI_CHAP_PASSWORD"); - - tmp = strchr(portal, '@'); - if (tmp != NULL) { - user = portal; - *tmp++ = 0; - portal = tmp; - - tmp = strchr(user, '%'); - if (tmp != NULL) { - *tmp++ = 0; - passwd = tmp; - } - } - - - iscsi_url = malloc(sizeof(struct iscsi_url)); - if (iscsi_url == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to allocate iscsi_url structure"); - free(str); - return NULL; - } - memset(iscsi_url, 0, sizeof(struct iscsi_url)); - - iscsi_url->portal = strdup(portal); - if (iscsi_url->portal == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup portal string"); - iscsi_destroy_url(iscsi_url); - free(str); - return NULL; - } - - if (user != NULL && passwd != NULL) { - iscsi_url->user = strdup(user); - if (iscsi_url->user == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup username string"); - iscsi_destroy_url(iscsi_url); - free(str); - return NULL; - } - - iscsi_url->passwd = strdup(passwd); - if (iscsi_url->passwd == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup password string"); - iscsi_destroy_url(iscsi_url); - free(str); - return NULL; - } - } - - free(str); - return iscsi_url; + return iscsi_parse_url(iscsi,url,0); } void iscsi_destroy_url(struct iscsi_url *iscsi_url) { - if (iscsi_url == NULL) { - return; - } - - free(discard_const(iscsi_url->portal)); - free(discard_const(iscsi_url->target)); - free(discard_const(iscsi_url->user)); - free(discard_const(iscsi_url->passwd)); free(iscsi_url); } @@ -589,19 +436,7 @@ int iscsi_set_initiator_username_pwd(struct iscsi_context *iscsi, const char *user, const char *passwd) { - free(discard_const(iscsi->user)); - iscsi->user = strdup(user); - if (iscsi->user == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: failed to strdup username"); - return -1; - } - - free(discard_const(iscsi->passwd)); - iscsi->passwd = strdup(passwd); - if (iscsi->passwd == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: failed to strdup password"); - return -1; - } - + strncpy(iscsi->user,user,MAX_STRING_SIZE); + strncpy(iscsi->passwd,passwd,MAX_STRING_SIZE); return 0; } diff --git a/lib/login.c b/lib/login.c index 8e57839..5da4d21 100644 --- a/lib/login.c +++ b/lib/login.c @@ -106,7 +106,7 @@ iscsi_login_add_targetname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu) return 0; } - if (iscsi->target_name == NULL) { + if (!iscsi->target_name[0]) { iscsi_set_error(iscsi, "Trying normal connect but " "target name not set."); return -1; @@ -663,7 +663,7 @@ iscsi_login_add_chap_response(struct iscsi_context *iscsi, struct iscsi_pdu *pdu return 0; } - if (iscsi->chap_c == NULL) { + if (!iscsi->chap_c[0]) { iscsi_set_error(iscsi, "No CHAP challenge found"); return -1; } @@ -748,7 +748,7 @@ iscsi_login_async(struct iscsi_context *iscsi, iscsi_command_cb cb, /* login request */ iscsi_pdu_set_immediate(pdu); - if (iscsi->user == NULL) { + if (!iscsi->user[0]) { iscsi->current_phase = ISCSI_PDU_LOGIN_CSG_OPNEG; } @@ -1008,15 +1008,7 @@ iscsi_process_login_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, /* parse the strings */ if (!strncmp(ptr, "TargetAddress=", 14)) { - free(discard_const(iscsi->target_address)); - iscsi->target_address = strdup(ptr+14); - if (iscsi->target_address == NULL) { - iscsi_set_error(iscsi, "Failed to allocate" - " target address"); - pdu->callback(iscsi, SCSI_STATUS_ERROR, NULL, - pdu->private_data); - return -1; - } + strncpy(iscsi->target_address,ptr+14,MAX_STRING_SIZE); } if (!strncmp(ptr, "HeaderDigest=", 13)) { @@ -1074,13 +1066,7 @@ iscsi_process_login_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, } if (!strncmp(ptr, "CHAP_C=0x", 9)) { - free(iscsi->chap_c); - iscsi->chap_c = strdup(ptr+9); - if (iscsi->chap_c == NULL) { - iscsi_set_error(iscsi, "Out-of-memory: Failed to strdup CHAP challenge."); - pdu->callback(iscsi, SCSI_STATUS_ERROR, NULL, pdu->private_data); - return -1; - } + strncpy(iscsi->chap_c,ptr+9,MAX_STRING_SIZE); iscsi->secneg_phase = ISCSI_LOGIN_SECNEG_PHASE_SEND_RESPONSE; } diff --git a/lib/socket.c b/lib/socket.c index 16b194f..68c6a13 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -228,8 +228,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal, freeaddrinfo(ai); - if (iscsi->connected_portal) free(discard_const(iscsi->connected_portal)); - iscsi->connected_portal=strdup(portal); + strncpy(iscsi->connected_portal,portal,MAX_STRING_SIZE); return 0; } @@ -245,7 +244,7 @@ iscsi_disconnect(struct iscsi_context *iscsi) close(iscsi->fd); - if (iscsi->connected_portal) + if (iscsi->connected_portal[0]) DPRINTF(iscsi,2,"disconnected from portal %s",iscsi->connected_portal); iscsi->fd = -1; @@ -522,12 +521,12 @@ iscsi_service(struct iscsi_context *iscsi, int revents) return 0; } - if (revents & POLLOUT && iscsi->outqueue != NULL) { + if (iscsi->is_connected && revents & POLLOUT && iscsi->outqueue != NULL) { if (iscsi_write_to_socket(iscsi) != 0) { return iscsi_service_reconnect_if_loggedin(iscsi); } } - if (revents & POLLIN) { + if (iscsi->is_connected && revents & POLLIN) { if (iscsi_read_from_socket(iscsi) != 0) { return iscsi_service_reconnect_if_loggedin(iscsi); } diff --git a/src/iscsi-inq.c b/src/iscsi-inq.c index 87b6d35..031e4e3 100644 --- a/src/iscsi-inq.c +++ b/src/iscsi-inq.c @@ -216,7 +216,7 @@ int main(int argc, const char *argv[]) struct iscsi_context *iscsi; const char **extra_argv; int extra_argc = 0; - const char *url = NULL; + char *url = NULL; struct iscsi_url *iscsi_url = NULL; int evpd = 0, pagecode = 0; int show_help = 0, show_usage = 0, debug = 0; @@ -275,6 +275,9 @@ int main(int argc, const char *argv[]) exit(10); } iscsi_url = iscsi_parse_full_url(iscsi, url); + + if (url) free(url); + if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", iscsi_get_error(iscsi)); diff --git a/src/iscsi-ls.c b/src/iscsi-ls.c index 6951a57..b8c4b7c 100644 --- a/src/iscsi-ls.c +++ b/src/iscsi-ls.c @@ -312,7 +312,7 @@ int main(int argc, const char *argv[]) struct client_state state; const char **extra_argv; int extra_argc = 0; - const char *url = NULL; + char *url = NULL; poptContext pc; int res; int show_help = 0, show_usage = 0, debug = 0; @@ -367,11 +367,14 @@ int main(int argc, const char *argv[]) exit(10); } - if (debug > 0) { - iscsi_set_debug(iscsi, debug); - } + if (debug > 0) { + iscsi_set_debug(iscsi, debug); + } iscsi_url = iscsi_parse_portal_url(iscsi, url); + + if (url) free(url); + if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", iscsi_get_error(iscsi)); diff --git a/src/iscsi-readcapacity16.c b/src/iscsi-readcapacity16.c index 5f76de0..bbbc38f 100644 --- a/src/iscsi-readcapacity16.c +++ b/src/iscsi-readcapacity16.c @@ -58,7 +58,7 @@ int main(int argc, const char *argv[]) struct iscsi_context *iscsi; const char **extra_argv; int extra_argc = 0; - const char *url = NULL; + char *url = NULL; struct iscsi_url *iscsi_url = NULL; int show_help = 0, show_usage = 0, debug = 0, size_only=0; int res; @@ -117,6 +117,9 @@ int main(int argc, const char *argv[]) exit(10); } iscsi_url = iscsi_parse_full_url(iscsi, url); + + if (url) free(url); + if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", iscsi_get_error(iscsi)); diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index 5ea3705..27e61cf 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -437,6 +437,8 @@ int main(int argc, const char *argv[]) if (url == NULL) { fprintf(stderr, "You must specify the URL\n"); print_usage(); + free(skipname); + free(testname); exit(10); } @@ -474,6 +476,10 @@ int main(int argc, const char *argv[]) printf("\n"); } + free(skipname); + free(testname); + free(url); + return num_failed ? num_failed : num_skipped ? 77 : 0; }