Add flush_my_map_info_list() and fix a bug in the Mac load_map_info_list().
(If you fclose(3) rather than pclose(3) a FILE* you got from popen(3),
future popen(3)s fail obscurely, at least on Mac OS.)
(cherry picked from commit 2bf76e143da933184d1392fb9bea3a3896c37e76)
Change-Id: I5578fe06753061b0dbc5ee951ebf31eb2bab0389
diff --git a/libcorkscrew/map_info.c b/libcorkscrew/map_info.c
index 00e901e..93dffbf 100644
--- a/libcorkscrew/map_info.c
+++ b/libcorkscrew/map_info.c
@@ -83,7 +83,7 @@
milist = mi;
}
}
- fclose(fp);
+ pclose(fp);
return milist;
}
@@ -220,7 +220,7 @@
pthread_mutex_lock(&g_my_map_info_list_mutex);
int64_t time = now_ns();
- if (g_my_map_info_list) {
+ if (g_my_map_info_list != NULL) {
my_map_info_data_t* data = (my_map_info_data_t*)g_my_map_info_list->data;
int64_t age = time - data->timestamp;
if (age >= MAX_CACHE_AGE) {
@@ -232,10 +232,10 @@
}
}
- if (!g_my_map_info_list) {
+ if (g_my_map_info_list == NULL) {
my_map_info_data_t* data = (my_map_info_data_t*)malloc(sizeof(my_map_info_data_t));
g_my_map_info_list = load_map_info_list(getpid());
- if (g_my_map_info_list) {
+ if (g_my_map_info_list != NULL) {
ALOGV("Loaded my_map_info_list %p.", g_my_map_info_list);
g_my_map_info_list->data = data;
data->refs = 1;
@@ -265,3 +265,15 @@
pthread_mutex_unlock(&g_my_map_info_list_mutex);
}
}
+
+void flush_my_map_info_list() {
+ pthread_mutex_lock(&g_my_map_info_list_mutex);
+
+ if (g_my_map_info_list != NULL) {
+ my_map_info_data_t* data = (my_map_info_data_t*) g_my_map_info_list->data;
+ dec_ref(g_my_map_info_list, data);
+ g_my_map_info_list = NULL;
+ }
+
+ pthread_mutex_unlock(&g_my_map_info_list_mutex);
+}