aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-helper-transport-bluetooth.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-17 20:20:21 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-17 20:20:21 +0000
commite41de7ea55c318ee24a707a1002b69ba1c6402d1 (patch)
tree36a0ea79d9ee1fabe94ac52547f830e1227122c8 /src/transport/gnunet-helper-transport-bluetooth.c
parent1d95d0827882e8050289b9a53c532d83c5dd8958 (diff)
downloadgnunet-e41de7ea55c318ee24a707a1002b69ba1c6402d1.tar.gz
gnunet-e41de7ea55c318ee24a707a1002b69ba1c6402d1.zip
-fix socket leak in error handling branches
Diffstat (limited to 'src/transport/gnunet-helper-transport-bluetooth.c')
-rw-r--r--src/transport/gnunet-helper-transport-bluetooth.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c
index 8ccfe6377..af460c832 100644
--- a/src/transport/gnunet-helper-transport-bluetooth.c
+++ b/src/transport/gnunet-helper-transport-bluetooth.c
@@ -1080,7 +1080,7 @@ read_from_the_socket (void *sock,
1080 * Open the bluetooth interface for reading/writing 1080 * Open the bluetooth interface for reading/writing
1081 * 1081 *
1082 * @param dev pointer to the device struct 1082 * @param dev pointer to the device struct
1083 * @return 0 on success 1083 * @return 0 on success, non-zero on error
1084 */ 1084 */
1085static int 1085static int
1086open_device (struct HardwareInfos *dev) 1086open_device (struct HardwareInfos *dev)
@@ -1140,7 +1140,9 @@ open_device (struct HardwareInfos *dev)
1140 1140
1141 if (fd_hci < 0) 1141 if (fd_hci < 0)
1142 { 1142 {
1143 fprintf (stderr, "Failed to create HCI socket: %s\n", strerror (errno)); 1143 fprintf (stderr,
1144 "Failed to create HCI socket: %s\n",
1145 strerror (errno));
1144 return -1; 1146 return -1;
1145 } 1147 }
1146 1148
@@ -1149,8 +1151,12 @@ open_device (struct HardwareInfos *dev)
1149 1151
1150 if (ioctl (fd_hci, HCIGETDEVLIST, (void *) &request) < 0) 1152 if (ioctl (fd_hci, HCIGETDEVLIST, (void *) &request) < 0)
1151 { 1153 {
1152 fprintf (stderr, "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n", 1154 fprintf (stderr,
1153 IFNAMSIZ, dev->iface, strerror (errno)); 1155 "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n",
1156 IFNAMSIZ,
1157 dev->iface,
1158 strerror (errno));
1159 (void) close (fd_hci);
1154 return 1; 1160 return 1;
1155 } 1161 }
1156 1162
@@ -1165,8 +1171,12 @@ open_device (struct HardwareInfos *dev)
1165 1171
1166 if (ioctl (fd_hci, HCIGETDEVINFO, (void *) &dev_info)) 1172 if (ioctl (fd_hci, HCIGETDEVINFO, (void *) &dev_info))
1167 { 1173 {
1168 fprintf (stderr, "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n", 1174 fprintf (stderr,
1169 IFNAMSIZ, dev->iface, strerror (errno)); 1175 "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n",
1176 IFNAMSIZ,
1177 dev->iface,
1178 strerror (errno));
1179 (void) close (fd_hci);
1170 return 1; 1180 return 1;
1171 } 1181 }
1172 1182
@@ -1185,8 +1195,12 @@ open_device (struct HardwareInfos *dev)
1185 /* Bring the interface up */ 1195 /* Bring the interface up */
1186 if (ioctl (fd_hci, HCIDEVUP, dev_info.dev_id)) 1196 if (ioctl (fd_hci, HCIDEVUP, dev_info.dev_id))
1187 { 1197 {
1188 fprintf (stderr, "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n", 1198 fprintf (stderr,
1189 IFNAMSIZ, dev->iface, strerror (errno)); 1199 "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n",
1200 IFNAMSIZ,
1201 dev->iface,
1202 strerror (errno));
1203 (void) close (fd_hci);
1190 return 1; 1204 return 1;
1191 } 1205 }
1192 } 1206 }
@@ -1204,8 +1218,12 @@ open_device (struct HardwareInfos *dev)
1204 1218
1205 if (ioctl (fd_hci, HCISETSCAN, (unsigned long) &dev_req)) 1219 if (ioctl (fd_hci, HCISETSCAN, (unsigned long) &dev_req))
1206 { 1220 {
1207 fprintf (stderr, "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n", 1221 fprintf (stderr,
1208 IFNAMSIZ, dev->iface, strerror (errno)); 1222 "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n",
1223 IFNAMSIZ,
1224 dev->iface,
1225 strerror (errno));
1226 (void) close (fd_hci);
1209 return 1; 1227 return 1;
1210 } 1228 }
1211 1229
@@ -1216,9 +1234,12 @@ open_device (struct HardwareInfos *dev)
1216 } 1234 }
1217 1235
1218 /* Check if the interface was not found */ 1236 /* Check if the interface was not found */
1219 if (dev_id == -1) 1237 if (-1 == dev_id)
1220 { 1238 {
1221 fprintf (stderr, "The interface %s was not found\n", dev->iface); 1239 fprintf (stderr,
1240 "The interface %s was not found\n",
1241 dev->iface);
1242 (void) close (fd_hci);
1222 return 1; 1243 return 1;
1223 } 1244 }
1224 1245
@@ -1234,15 +1255,20 @@ open_device (struct HardwareInfos *dev)
1234 1255
1235 if (bind_socket (dev->fd_rfcomm, &rc_addr) != 0) 1256 if (bind_socket (dev->fd_rfcomm, &rc_addr) != 0)
1236 { 1257 {
1237 fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, 1258 fprintf (stderr,
1238 dev->iface, strerror (errno)); 1259 "Failed to bind interface `%.*s': %s\n",
1260 IFNAMSIZ,
1261 dev->iface,
1262 strerror (errno));
1239 return 1; 1263 return 1;
1240 } 1264 }
1241 1265
1242 /* Register a SDP service */ 1266 /* Register a SDP service */
1243 if (register_service (dev, rc_addr.rc_channel) != 0) 1267 if (register_service (dev, rc_addr.rc_channel) != 0)
1244 { 1268 {
1245 fprintf (stderr, "Failed to register a service on interface `%.*s': %s\n", IFNAMSIZ, 1269 fprintf (stderr,
1270 "Failed to register a service on interface `%.*s': %s\n",
1271 IFNAMSIZ,
1246 dev->iface, strerror (errno)); 1272 dev->iface, strerror (errno));
1247 return 1; 1273 return 1;
1248 } 1274 }