Skip to content

Commit 3eeb0e7

Browse files
committedDec 12, 2016
cb fix
1 parent 02ea1b5 commit 3eeb0e7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed
 

‎pdevice_monitor.c

+16-12
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,27 @@
2727

2828

2929
#define MAX_LOADSTRING 100
30-
device_event_callback *callbacks;
30+
static device_event_callback *callbacks;
3131
static int clbsize = 10;
3232
static int clbnum = 0;
3333

3434

3535
void padd_monitor_callback(device_event_callback callback) {
36-
if (clbnum == 0)
37-
callbacks = (device_event_callback *)psync_malloc(sizeof(callbacks)*clbsize);
38-
else {
39-
while (clbnum > clbsize) {
40-
device_event_callback *callbacks_old = callbacks;
41-
clbsize = clbsize * 2;
42-
callbacks = (device_event_callback *)psync_malloc(sizeof(callbacks)*clbsize);
43-
psync_free(callbacks_old);
44-
}
45-
}
46-
callbacks[clbnum++] = callback;
36+
if (callback) {
37+
if (clbnum == 0)
38+
callbacks = (device_event_callback *)psync_malloc(sizeof(device_event_callback)*clbsize);
39+
else {
40+
while (clbnum > clbsize) {
41+
device_event_callback *callbacks_old = callbacks;
42+
callbacks = (device_event_callback *)psync_malloc(sizeof(device_event_callback)*clbsize*2);
43+
memccpy(callbacks, callbacks_old, 0,sizeof(device_event_callback)*clbsize);
44+
clbsize = clbsize * 2;
45+
psync_free(callbacks_old);
46+
}
47+
}
48+
callbacks[clbnum] = callback;
49+
clbnum++;
50+
}
4751
}
4852

4953
static pdevice_info * new_dev_info( char *szPath, pdevice_types type, device_event evt) {

0 commit comments

Comments
 (0)
Please sign in to comment.