From f18e4b4457f6bf11f7cb43eee5723daef2720d85 Mon Sep 17 00:00:00 2001 From: Ross Philipson Date: Fri, 1 May 2009 14:47:39 +0000 Subject: [PATCH] Fixes to use dlerror() to test dlsym() calls and fixed possible realloc() leak. Committer: Ross Philipson Changes to be committed: modified: libs/scsi/scsi_inq_stubs.c --- libs/scsi/scsi_inq_stubs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/scsi/scsi_inq_stubs.c b/libs/scsi/scsi_inq_stubs.c index f55e6e6..ba0e775 100644 --- a/libs/scsi/scsi_inq_stubs.c +++ b/libs/scsi/scsi_inq_stubs.c @@ -98,22 +98,23 @@ static int scsi_inq_open_device(struct sg_inst *inst, const char *device) return SI_ERR_FAILURE; do { + dlerror(); /* clear */ /* locate the function we need to make the scsi inquries */ inst->sg_cmds_open_device_fn = (sg_cmds_open_device_t)dlsym(handle, "sg_cmds_open_device"); - if (!inst->sg_cmds_open_device_fn) + if (dlerror()) break; inst->sg_cmds_close_device_fn = (sg_cmds_close_device_t)dlsym(handle, "sg_cmds_close_device"); - if (!inst->sg_cmds_close_device_fn) + if (dlerror()) break; inst->sg_ll_inquiry_fn = (sg_ll_inquiry_t)dlsym(handle, "sg_ll_inquiry"); - if (!inst->sg_ll_inquiry_fn) + if (dlerror()) break; inst->sg_vpd_dev_id_iter_fn = (sg_vpd_dev_id_iter_t)dlsym(handle, "sg_vpd_dev_id_iter"); - if (!inst->sg_vpd_dev_id_iter_fn) + if (dlerror()) break; /* open the scsi/ata device */ @@ -195,7 +196,8 @@ static int scsi_do_vpd_inq(struct sg_inst *inst, struct scsi_inq_data *si_data, if (length > SI_MAX_LEN) break; if (length > SI_DEFAULT_LEN) { - rbuf = realloc(rbuf, length); + free(rbuf); + rbuf = malloc(length); if (!rbuf) { rc = SI_ERR_OUTOFMEM; break; -- 2.39.5